Package org.apache.zookeeper
Class Shell.ShellCommandExecutor
java.lang.Object
org.apache.zookeeper.Shell
org.apache.zookeeper.Shell.ShellCommandExecutor
- Enclosing class:
Shell
A simple shell command executor.
ShellCommandExecutor
should 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.zookeeper.Shell
Shell.ExitCodeException, Shell.ShellCommandExecutor
-
Field Summary
Fields inherited from class org.apache.zookeeper.Shell
SET_GROUP_COMMAND, SET_OWNER_COMMAND, SET_PERMISSION_COMMAND, timeOutInterval, ULIMIT_COMMAND, USER_NAME_COMMAND, WINDOWS
-
Constructor Summary
ConstructorsConstructorDescriptionShellCommandExecutor
(String[] execString) ShellCommandExecutor
(String[] execString, File dir) Create a new instance of the ShellCommandExecutor to execute a command. -
Method Summary
Modifier and TypeMethodDescriptionvoid
execute()
Execute the shell command.protected String[]
return an array containing the command name and its parametersGet the output of the shell command.protected void
parseExecResult
(BufferedReader lines) Parse the execution resulttoString()
Returns the commands of this instance.Methods inherited from class org.apache.zookeeper.Shell
execCommand, execCommand, execCommand, getExitCode, getGET_PERMISSION_COMMAND, getGroupsCommand, getGroupsForUserCommand, getProcess, getUlimitMemoryCommand, isTimedOut, run, setEnvironment, setWorkingDirectory
-
Constructor Details
-
ShellCommandExecutor
-
ShellCommandExecutor
-
ShellCommandExecutor
-
ShellCommandExecutor
Create a new instance of the ShellCommandExecutor to execute a command.- Parameters:
execString
- The command to execute with argumentsdir
- 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 Details
-
execute
Execute the shell command.- Throws:
IOException
-
getExecString
Description copied from class:Shell
return an array containing the command name and its parameters- Specified by:
getExecString
in classShell
-
parseExecResult
Description copied from class:Shell
Parse the execution result- Specified by:
parseExecResult
in classShell
- Throws:
IOException
-
getOutput
Get the output of the shell command. -
toString
Returns the commands of this instance. Arguments with spaces in are presented with quotes round; other arguments are presented raw
-