public static class Shell.ShellCommandExecutor extends Shell implements Shell.CommandExecutor
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.Shell.CommandExecutor, Shell.ExitCodeException, Shell.OSType, Shell.ShellCommandExecutor
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 and Description |
---|
Shell.ShellCommandExecutor(String[] execString) |
Shell.ShellCommandExecutor(String[] execString,
File dir) |
Shell.ShellCommandExecutor(String[] execString,
File dir,
Map<String,String> env) |
Shell.ShellCommandExecutor(String[] execString,
File dir,
Map<String,String> env,
long timeout) |
Shell.ShellCommandExecutor(String[] execString,
File dir,
Map<String,String> env,
long timeout,
boolean inheritParentEnv)
Create a new instance of the ShellCommandExecutor to execute a command.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
execute()
Execute the shell command.
|
String[] |
getExecString()
return an array containing the command name and its parameters.
|
String |
getOutput()
Get the output of the shell command.
|
protected void |
parseExecResult(BufferedReader lines)
Parse the execution result
|
String |
toString()
Returns the commands of this instance.
|
appendScriptExtension, appendScriptExtension, checkIsBashSupported, checkWindowsCommandLineLength, execCommand, execCommand, execCommand, getCheckProcessIsAliveCommand, getEnvironment, getEnvironmentVariableRegex, getExitCode, getGetPermissionCommand, getGroupsCommand, getGroupsForUserCommand, getGroupsIDForUserCommand, getHadoopHome, getProcess, getQualifiedBin, getQualifiedBinPath, getReadlinkCommand, getRunScriptCommand, getSetOwnerCommand, getSetPermissionCommand, getSetPermissionCommand, getSignalKillCommand, getSymlinkCommand, getUsersForNetgroupCommand, getWinUtilsFile, getWinUtilsPath, hasWinutilsPath, isJava7OrAbove, isTimedOut, run, setEnvironment, setWorkingDirectory
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getExitCode
public Shell.ShellCommandExecutor(String[] execString)
public Shell.ShellCommandExecutor(String[] execString, File dir)
public Shell.ShellCommandExecutor(String[] execString, File dir, Map<String,String> env)
public Shell.ShellCommandExecutor(String[] execString, File dir, Map<String,String> env, long timeout)
public Shell.ShellCommandExecutor(String[] execString, File dir, Map<String,String> env, long timeout, boolean inheritParentEnv)
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.public void execute() throws IOException
execute
in interface Shell.CommandExecutor
IOException
- if the command fails, or if the command is
not well constructed.public String[] getExecString()
Shell
getExecString
in class Shell
protected void parseExecResult(BufferedReader lines) throws IOException
Shell
parseExecResult
in class Shell
IOException
public String getOutput()
getOutput
in interface Shell.CommandExecutor
public String toString()
public void close()
close
in interface Shell.CommandExecutor
Copyright © 2017 Apache Software Foundation. All Rights Reserved.