Package org.apache.bookkeeper.util
Class Shell.ShellCommandExecutor
- java.lang.Object
- 
- org.apache.bookkeeper.util.Shell
- 
- org.apache.bookkeeper.util.Shell.ShellCommandExecutor
 
 
- 
- Enclosing class:
- Shell
 
 public static class Shell.ShellCommandExecutor extends Shell A simple shell command executor.ShellCommandExecutorshould be used in cases where the output of the command needs no explicit parsing and where the command, working directory and the environment remains unchanged. The output of the command is stored as-is and is expected to be small.
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from class org.apache.bookkeeper.util.ShellShell.ExitCodeException, Shell.ShellCommandExecutor
 
- 
 - 
Field Summary- 
Fields inherited from class org.apache.bookkeeper.util.ShellLOG, timeOutInterval, WINDOWS
 
- 
 - 
Constructor SummaryConstructors Constructor Description ShellCommandExecutor(java.lang.String[] execString)ShellCommandExecutor(java.lang.String[] execString, java.io.File dir)ShellCommandExecutor(java.lang.String[] execString, java.io.File dir, java.util.Map<java.lang.String,java.lang.String> env)ShellCommandExecutor(java.lang.String[] execString, java.io.File dir, java.util.Map<java.lang.String,java.lang.String> env, long timeout)Create a new instance of the ShellCommandExecutor to execute a command.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidexecute()Execute the shell command.java.lang.String[]getExecString()Return an array containing the command name & its parameters.java.lang.StringgetOutput()Get the output of the shell command.protected voidparseExecResult(java.io.BufferedReader lines)Parse the execution result.java.lang.StringtoString()Returns the commands of this instance.- 
Methods inherited from class org.apache.bookkeeper.util.ShellexecCommand, execCommand, execCommand, getExitCode, getProcess, isTimedOut, run, setEnvironment, setWorkingDirectory
 
- 
 
- 
- 
- 
Constructor Detail- 
ShellCommandExecutorpublic ShellCommandExecutor(java.lang.String[] execString) 
 - 
ShellCommandExecutorpublic ShellCommandExecutor(java.lang.String[] execString, java.io.File dir)
 - 
ShellCommandExecutorpublic ShellCommandExecutor(java.lang.String[] execString, java.io.File dir, java.util.Map<java.lang.String,java.lang.String> env)
 - 
ShellCommandExecutorpublic ShellCommandExecutor(java.lang.String[] execString, java.io.File dir, java.util.Map<java.lang.String,java.lang.String> env, long timeout)Create a new instance of the ShellCommandExecutor to execute a command.- Parameters:
- execString- The command to execute with arguments
- dir- If not-null, specifies the directory which should be set as the current working directory for the command. If null, the current working directory is not modified.
- env- If not-null, environment of the command will include the key-value pairs specified in the map. If null, the current environment is not modified.
- timeout- Specifies the time in milliseconds, after which the command will be killed and the status marked as timedout. If 0, the command will not be timed out.
 
 
- 
 - 
Method Detail- 
executepublic void execute() throws java.io.IOExceptionExecute the shell command.- Throws:
- java.io.IOException
 
 - 
getExecStringpublic java.lang.String[] getExecString() Description copied from class:ShellReturn an array containing the command name & its parameters.- Specified by:
- getExecStringin class- Shell
 
 - 
parseExecResultprotected void parseExecResult(java.io.BufferedReader lines) throws java.io.IOExceptionDescription copied from class:ShellParse the execution result.- Specified by:
- parseExecResultin class- Shell
- Throws:
- java.io.IOException
 
 - 
getOutputpublic java.lang.String getOutput() Get the output of the shell command.
 - 
toStringpublic java.lang.String toString() Returns the commands of this instance. Arguments with spaces in are presented with quotes round; other arguments are presented raw- Overrides:
- toStringin class- java.lang.Object
- Returns:
- a string representation of the object.
 
 
- 
 
-