Package org.apache.hadoop.util
Class Shell.ShellCommandExecutor
java.lang.Object
org.apache.hadoop.util.Shell
org.apache.hadoop.util.Shell.ShellCommandExecutor
- All Implemented Interfaces:
Shell.CommandExecutor
- Enclosing class:
- 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.hadoop.util.Shell
Shell.CommandExecutor, Shell.ExitCodeException, Shell.OSType, Shell.ShellCommandExecutor -
Field Summary
Fields inherited from class org.apache.hadoop.util.Shell
ENV_HADOOP_HOME, ENV_NAME_REGEX, FREEBSD, inheritParentEnv, isSetsidAvailable, LINK_COMMAND, LINUX, LOG, MAC, osType, OTHER, PPC_64, READ_LINK_COMMAND, SET_GROUP_COMMAND, SET_OWNER_COMMAND, SET_PERMISSION_COMMAND, SOLARIS, SYSPROP_HADOOP_HOME_DIR, timeOutInterval, TOKEN_SEPARATOR_REGEX, USER_NAME_COMMAND, WINDOWS, WINDOWS_MAX_SHELL_LENGHT, WINDOWS_MAX_SHELL_LENGTH, WindowsProcessLaunchLock, WINUTILS -
Constructor Summary
ConstructorsConstructorDescriptionShellCommandExecutor(String[] execString) ShellCommandExecutor(String[] execString, File dir) ShellCommandExecutor(String[] execString, File dir, Map<String, String> env, long timeout, boolean inheritParentEnv) Create a new instance of the ShellCommandExecutor to execute a command. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidexecute()Execute the shell command.String[]return an array containing the command name and its parameters.Get the output of the shell command.longReturns the timeout value set for the executor's sub-commands.protected voidparseExecResult(BufferedReader lines) Parse the execution result.toString()Returns the commands of this instance.Methods inherited from class org.apache.hadoop.util.Shell
appendScriptExtension, appendScriptExtension, bashQuote, checkIsBashSupported, checkWindowsCommandLineLength, destroyAllShellProcesses, execCommand, execCommand, execCommand, getAllShells, getCheckProcessIsAliveCommand, getEnvironment, getEnvironmentVariableRegex, getExitCode, getGetPermissionCommand, getGroupsCommand, getGroupsForUserCommand, getGroupsIDForUserCommand, getHadoopHome, getMemlockLimit, getProcess, getQualifiedBin, getQualifiedBinPath, getReadlinkCommand, getRunScriptCommand, getSetOwnerCommand, getSetPermissionCommand, getSetPermissionCommand, getSignalKillCommand, getSymlinkCommand, getUsersForNetgroupCommand, getWaitingThread, getWinUtilsFile, getWinUtilsPath, hasWinutilsPath, isJava7OrAbove, isJavaVersionAtLeast, isTimedOut, run, setEnvironment, setWorkingDirectoryMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.hadoop.util.Shell.CommandExecutor
getExitCode
-
Constructor Details
-
ShellCommandExecutor
-
ShellCommandExecutor
-
ShellCommandExecutor
-
ShellCommandExecutor
-
ShellCommandExecutor
public ShellCommandExecutor(String[] execString, File dir, Map<String, String> env, long timeout, boolean inheritParentEnv) 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 timed-out. If 0, the command will not be timed out.inheritParentEnv- Indicates if the process should inherit the env vars from the parent process or not.
-
-
Method Details
-
getTimeoutInterval
@VisibleForTesting public long getTimeoutInterval()Returns the timeout value set for the executor's sub-commands.- Returns:
- The timeout value in milliseconds
-
execute
Execute the shell command.- Specified by:
executein interfaceShell.CommandExecutor- Throws:
IOException- if the command fails, or if the command is not well constructed.
-
getExecString
Description copied from class:Shellreturn an array containing the command name and its parameters.- Specified by:
getExecStringin classShell- Returns:
- exec string array.
-
parseExecResult
Description copied from class:ShellParse the execution result.- Specified by:
parseExecResultin classShell- Parameters:
lines- lines.- Throws:
IOException- raised on errors performing I/O.
-
getOutput
Get the output of the shell command.- Specified by:
getOutputin interfaceShell.CommandExecutor
-
toString
Returns the commands of this instance. Arguments with spaces in are presented with quotes round; other arguments are presented raw -
close
public void close()- Specified by:
closein interfaceShell.CommandExecutor
-