public class CommandRunner extends Object implements AutoCloseable, com.helger.commons.lang.ICloneable<CommandRunner>
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 |
m_aSessionManager |
| Constructor and Description |
|---|
CommandRunner(ISessionFactory 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.ExecuteResult |
execute(String command)
Executes
command and returns the result. |
CommandRunner |
getClone()
Returns a new CommandRunner with the same SessionFactory, but will create a
separate session.
|
CommandRunner.ChannelExecWrapper |
open(String command)
Executes
command and returns an execution wrapper that
provides safe access to and management of the underlying streams of data. |
protected final SessionManager m_aSessionManager
public CommandRunner(@Nonnull ISessionFactory sessionFactory)
SessionManager that
wraps the supplied sessionFactory.sessionFactory - The factory used to create a session managerpublic void close()
throws IOException
SessionManager.close in interface AutoCloseableIOExceptionSessionManager.close()@Nonnull @ReturnsMutableCopy public CommandRunner getClone()
getClone in interface com.helger.commons.lang.ICloneable<CommandRunner>public CommandRunner.ExecuteResult execute(String command) throws com.jcraft.jsch.JSchException, 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 failsIOException - If unable to read the result data@Nonnull public CommandRunner.ChannelExecWrapper open(String command) throws com.jcraft.jsch.JSchException, 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 failsIOException - If unable to read the result dataCopyright © 2020 Philip Helger. All rights reserved.