public interface CommandLineExecutor
The interface allows to
The following example shows the basic usage:
Executor exec = new DefaultExecutor();
CommandLine cl = new CommandLine("ls -l");
int exitvalue = exec.execute(cl);
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
INVALID_EXITVALUE
Invalid exit code.
|
| 限定符和类型 | 方法和说明 |
|---|---|
int |
execute(boolean async,
CommandLine command) |
int |
execute(boolean async,
CommandLine command,
ExecuteResultHandler handler) |
int |
execute(boolean async,
CommandLine command,
Map<String,String> environment) |
int |
execute(boolean async,
CommandLine command,
Map<String,String> environment,
File workingDirectory,
ExecuteStreamHandler streamHandler,
ExecuteResultHandler handler) |
int |
execute(CommandLine command)
Methods for starting synchronous execution.
|
int |
execute(CommandLine command,
ExecuteResultHandler handler)
Methods for starting asynchronous execution.
|
int |
execute(CommandLine command,
Map<String,String> environment)
Methods for starting synchronous execution.
|
int |
execute(CommandLine command,
Map<String,String> environment,
File workingDirectory,
ExecuteStreamHandler streamHandler,
ExecuteResultHandler handler)
Methods for starting asynchronous execution.
|
InstructionSequenceDestroyer |
getProcessDestroyer()
Set the handler for cleanup of started processes if the main process
is going to terminate.
|
ExecuteResultHandler |
getResultHandler() |
ExecuteStreamHandler |
getStreamHandler() |
ExecuteWatchdog |
getWatchdog()
Get the watchdog used to kill of processes running,
typically, too long time.
|
File |
getWorkingDirectory()
Get the working directory of the created process.
|
boolean |
isFailure(int exitValue)
Checks whether
exitValue signals a failure. |
void |
setExitValue(int value)
Define the
exitValue of the process to be considered
successful. |
void |
setExitValues(int[] values)
Define a list of
exitValue of the process to be considered
successful. |
void |
setProcessDestroyer(InstructionSequenceDestroyer processDestroyer)
Get the handler for cleanup of started processes if the main process
is going to terminate.
|
void |
setResultHandler(ExecuteResultHandler resultHandler) |
void |
setStreamHandler(ExecuteStreamHandler streamHandler) |
void |
setWatchdog(ExecuteWatchdog watchDog)
Set the watchdog used to kill of processes running,
typically, too long time.
|
void |
setWorkingDirectory(File dir)
Set the working directory of the created process.
|
static final int INVALID_EXITVALUE
void setExitValue(int value)
exitValue of the process to be considered
successful.value - the exit code representing successful executionvoid setExitValues(int[] values)
exitValue of the process to be considered
successful. The caller can pass one of the following values
isFailure(int)values - a list of the exit codesboolean isFailure(int exitValue)
exitValue signals a failure. If no
exit values are set than the default conventions of the OS is
used. e.g. most OS regard an exit code of '0' as successful
execution and everything else as failure.exitValue - the exit value (return code) to be checkedtrue if exitValue signals a failureExecuteWatchdog getWatchdog()
void setWatchdog(ExecuteWatchdog watchDog)
watchDog - the watchdogInstructionSequenceDestroyer getProcessDestroyer()
void setProcessDestroyer(InstructionSequenceDestroyer processDestroyer)
processDestroyer - the ProcessDestroyerFile getWorkingDirectory()
void setWorkingDirectory(File dir)
dir - the working directoryint execute(CommandLine command) throws ExecuteException, IOException
command - the command to executeExecuteException - execution of subprocess failed or the
subprocess returned a exit value indicating a failure
setExitValue(int).IOExceptionint execute(boolean async,
CommandLine command)
throws ExecuteException,
IOException
int execute(CommandLine command, Map<String,String> environment) throws ExecuteException, IOException
command - the command to executeenvironment - The environment for the new process. If null, the
environment of the current process is used.ExecuteException - execution of subprocess failed or the
subprocess returned a exit value indicating a failure
setExitValue(int).IOExceptionint execute(boolean async,
CommandLine command,
Map<String,String> environment)
throws ExecuteException,
IOException
int execute(CommandLine command, ExecuteResultHandler handler) throws ExecuteException, IOException
command - the command to executehandler - capture process termination and exit codeExecuteException - execution of subprocess failedIOExceptionint execute(boolean async,
CommandLine command,
ExecuteResultHandler handler)
throws ExecuteException,
IOException
int execute(CommandLine command, Map<String,String> environment, File workingDirectory, ExecuteStreamHandler streamHandler, ExecuteResultHandler handler) throws ExecuteException, IOException
command - the command to executeenvironment - The environment for the new process. If null, the
environment of the current process is used.handler - capture process termination and exit codeExecuteException - execution of subprocess failedIOExceptionint execute(boolean async,
CommandLine command,
Map<String,String> environment,
File workingDirectory,
ExecuteStreamHandler streamHandler,
ExecuteResultHandler handler)
throws ExecuteException,
IOException
ExecuteStreamHandler getStreamHandler()
void setStreamHandler(ExecuteStreamHandler streamHandler)
ExecuteResultHandler getResultHandler()
void setResultHandler(ExecuteResultHandler resultHandler)
Copyright © 2021. All rights reserved.