public class CommandRunner
extends java.lang.Object
implements java.io.Closeable
exec channel. This
implementation offers a simplified interface to executing remote commands and
retrieving the results of execution.ChannelExec| Modifier and Type | Class and Description |
|---|---|
class |
CommandRunner.ChannelExecWrapper
Wraps the execution of a command to handle the opening and closing of all
the data streams for you.
|
class |
CommandRunner.ExecuteResult
A simple container for the results of a command execution.
|
| Modifier and Type | Field and Description |
|---|---|
protected SessionManager |
sessionManager |
protected static java.nio.charset.Charset |
UTF8 |
| Constructor and Description |
|---|
CommandRunner(SessionFactory sessionFactory)
Creates a new CommandRunner that will use a
SessionManager that
wraps the supplied sessionFactory. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the underlying
SessionManager. |
CommandRunner |
duplicate()
Returns a new CommandRunner with the same SessionFactory, but will
create a separate session.
|
CommandRunner.ExecuteResult |
execute(java.lang.String command)
Executes
command and returns the result. |
CommandRunner.ChannelExecWrapper |
open(java.lang.String command)
Executes
command and returns an execution wrapper that
provides safe access to and management of the underlying streams of data. |
protected static final java.nio.charset.Charset UTF8
protected final SessionManager sessionManager
public CommandRunner(SessionFactory sessionFactory)
SessionManager that
wraps the supplied sessionFactory.sessionFactory - The factory used to create a session managerpublic void close()
throws java.io.IOException
SessionManager.close in interface java.io.Closeableclose in interface java.lang.AutoCloseablejava.io.IOExceptionSessionManager.close()public CommandRunner duplicate()
public CommandRunner.ExecuteResult execute(java.lang.String command) throws com.jcraft.jsch.JSchException, java.io.IOException
command and returns the result. Use this method
when the command you are executing requires no input, writes only UTF-8
compatible text to STDOUT and/or STDERR, and you are comfortable with
buffering up all of that data in memory. Otherwise, use
open(String), which allows you to work with the underlying
streams.command - The command to executecom.jcraft.jsch.JSchException - If ssh execution failsjava.io.IOException - If unable to read the result datapublic CommandRunner.ChannelExecWrapper open(java.lang.String command) throws com.jcraft.jsch.JSchException, java.io.IOException
command and returns an execution wrapper that
provides safe access to and management of the underlying streams of data.command - The command to executecom.jcraft.jsch.JSchException - If ssh execution failsjava.io.IOException - If unable to read the result dataCopyright © 2018 pastdev.com. All Rights Reserved.