|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.ibm.are.common.CommandRunner
public class CommandRunner
The CommandRunner
class provides a level of abstraction to the Runtime.exec
method.
This class provides additional benefits, including the option to automatically retrieve all output sent
to standard out and error, as well as integrating with the same logging capabilities present in many other
ARE classes.
Field Summary | |
---|---|
static java.lang.String |
COPYRIGHT
Copyright for class bytecode |
Constructor Summary | |
---|---|
|
CommandRunner(java.lang.String command)
Constructs a CommandRunner object that will run the
specified command. |
|
CommandRunner(java.lang.String[] cmdarray)
Constructs a CommandRunner object that will run the
specified command. |
protected |
CommandRunner(java.lang.String[] envp,
java.io.File dir)
Constructs a CommandRunner object that will use the
specified environment variables and working directory for the sub-process
will be passed along on the Runtime.exec of the specified command. |
|
CommandRunner(java.lang.String[] cmdarray,
java.lang.String[] envp,
java.io.File dir)
Constructs a CommandRunner object that will run the
specified command. |
|
CommandRunner(java.lang.String command,
java.lang.String[] envp,
java.io.File dir)
Constructs a CommandRunner object that will run the
specified command. |
Method Summary | |
---|---|
java.lang.Object |
getCommand()
Retrieves the command to run |
int |
run()
Runs the command. |
int |
run(java.util.logging.Logger logger)
Runs the command. |
int |
run(StringList stdoutOutput,
StringList stderrOutput)
Runs the command. |
int |
run(StringList stdoutOutput,
StringList stderrOutput,
java.lang.String charSetName)
Runs the command. |
protected int |
runAndLog(StringList stdoutOutput,
StringList stderrOutput)
Runs the command, and uses a previously specified logger to log information. |
void |
setCommand(java.lang.String command)
Sets the command to run |
void |
setCommand(java.lang.String[] cmdarray)
Sets the command to run |
void |
setDir(java.io.File dir)
Sets the working directory for the sub-process that is created when the command is run |
void |
setEnv(java.lang.String[] envp)
Sets the environment variables that will be passed along and used by the sub-process that is created when the command is run. |
void |
setLogger(java.util.logging.Logger logger)
Associated a logger with the CommandRunner object. |
java.lang.String |
toString()
Returns a string representation of this class |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String COPYRIGHT
Constructor Detail |
---|
public CommandRunner(java.lang.String command, java.lang.String[] envp, java.io.File dir)
CommandRunner
object that will run the
specified command. The specified environment variables and working
directory for the sub-process will be passed along on the Runtime.exec
of
the specified command.
command
- The command to runenvp
- An array of environment variables to pass along to the sub-processdir
- The working directory for the sub-processpublic CommandRunner(java.lang.String[] cmdarray, java.lang.String[] envp, java.io.File dir)
CommandRunner
object that will run the
specified command. The specified environment variables and working
directory for the sub-process will be passed along on the Runtime.exec
of
the specified command.
cmdarray
- The command to runenvp
- An array of environment variables to pass along to the sub-processdir
- The working directory for the sub-processpublic CommandRunner(java.lang.String command)
CommandRunner
object that will run the
specified command.
command
- The command to runpublic CommandRunner(java.lang.String[] cmdarray)
CommandRunner
object that will run the
specified command.
cmdarray
- The command to runprotected CommandRunner(java.lang.String[] envp, java.io.File dir)
CommandRunner
object that will use the
specified environment variables and working directory for the sub-process
will be passed along on the Runtime.exec
of the specified command.
envp
- An array of environment variables to pass along to the sub-processdir
- The working directory for the sub-processMethod Detail |
---|
public java.lang.Object getCommand()
public void setCommand(java.lang.String command)
command
- The command to runpublic void setCommand(java.lang.String[] cmdarray)
cmdarray
- The command to runpublic void setLogger(java.util.logging.Logger logger)
CommandRunner
object. Any logging
that exists for the class will be sent to the specified logger.
logger
- The logger to associate with the CommandRunner
objectpublic void setEnv(java.lang.String[] envp)
envp
- An array of environment variables to pass along to the sub-processpublic void setDir(java.io.File dir)
dir
- The working directory for the sub-processpublic int run(StringList stdoutOutput, StringList stderrOutput, java.lang.String charSetName) throws java.io.IOException, java.lang.InterruptedException
null
, the character set specified
by the file.encoding system property is used to translate the output.
stdoutOutput
- All standard out output resulting from the running of the command will be placed in this liststderrOutput
- All standard error output resulting from the running of the command will be placed in this listcharSetName
- The name of the character set to use when translating standard out/err output. If no specific
character set should be used, null
should be passed for this parameter.
java.io.IOException
- If an I/O exception occurred while trying to run the command
java.lang.InterruptedException
- If the current thread is interrupted while waiting for the sub-process to completepublic int run(StringList stdoutOutput, StringList stderrOutput) throws java.io.IOException, java.lang.InterruptedException
stdoutOutput
- All standard out output resulting from the running of the command will be placed in this liststderrOutput
- All standard error output resulting from the running of the command will be placed in this list
java.io.IOException
- If an I/O exception occurred while trying to run the command
java.lang.InterruptedException
- If the current thread is interrupted while waiting for the sub-process to completepublic int run() throws java.io.IOException, java.lang.InterruptedException
java.io.IOException
- If an I/O exception occurred while trying to run the command
java.lang.InterruptedException
- If the current thread is interrupted while waiting for the sub-process to completepublic int run(java.util.logging.Logger logger) throws java.io.IOException, java.lang.InterruptedException
CommandRunner
class that
occurs during the setup or running of the command is sent to the specified logger.
logger
- The logger to log events to
java.io.IOException
- If an I/O exception occurred while trying to run the command
java.lang.InterruptedException
- If the current thread is interrupted while waiting for the sub-process to completeprotected int runAndLog(StringList stdoutOutput, StringList stderrOutput) throws java.io.IOException, java.lang.InterruptedException
stdoutOutput
- All standard out output resulting from the running of the command will be placed in this liststderrOutput
- All standard error output resulting from the running of the command will be placed in this list
java.io.IOException
- If an I/O exception occurred while trying to run the command
java.lang.InterruptedException
- If the current thread is interrupted while waiting for the sub-process to completepublic java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |