public class ProcessExecutor
extends java.lang.Object
Example :
ProcessExecutor executor = new ProcessExecutor("/bin/echo", "Hello World!");
executor.setCaptureOutput(true);
ProcessExecutionResult result = executor.execute();
assertEquals(0, result.getExitValue());
assertFalse(result.hasTimedOut());
assertEquals("Hello World!", result.getStdout().trim());
assertEquals("", result.getStderr());
Warning : A default timeout value of 10 minutes is defined by DEFAULT_TIMEOUT constant.setTimeout(long).| Modifier and Type | Class and Description |
|---|---|
class |
ProcessExecutor.ProcessExecutionResult
Holds process execution result.
|
| Modifier and Type | Field and Description |
|---|---|
static long |
DEFAULT_TIMEOUT
Default value in milliseconds for the maximum execution time of a
Process before is destroyed : 600000L
|
| Constructor and Description |
|---|
ProcessExecutor(java.util.List<java.lang.String> command)
Constructs a process executor with the specified operating
system program and arguments.
|
ProcessExecutor(java.lang.String... command)
Constructs a process executor with the specified operating
system program and arguments.
|
| Modifier and Type | Method and Description |
|---|---|
ProcessExecutor.ProcessExecutionResult |
execute()
Starts a new process using the attributes of this process executor and
wait for its termination (either naturally or through the default timeout).
|
java.lang.String |
getName()
Retrieve the name used to prefix any logs message and for threads name
|
long |
getTimeout()
Retrieve the maximum duration in milliseconds above which process is be stopped.
|
boolean |
isCaptureOutput()
Check if standard output and standard error have been requested for capture.
|
void |
setCaptureOutput(boolean captureOutput)
Set whether the standar output and standard error should be
captured in an internal string for use after process execution.
|
void |
setName(java.lang.String name)
Set the name used to prefix any logs message and for threads name
|
void |
setTimeout(long timeout)
Set the maximum duration in milliseconds above which process is stopped.
|
static java.lang.String[] |
splitCommandLine(java.lang.String cmdLine)
Split the specified command line String into a String array.
|
public static final long DEFAULT_TIMEOUT
public ProcessExecutor(java.util.List<java.lang.String> command)
command list. Subsequent
updates to the list will be reflected in the state of the
process builder. It is not checked whether
command corresponds to a valid operating system
command.command - The list containing the program and its argumentsjava.lang.NullPointerException - If the argument is nullpublic ProcessExecutor(java.lang.String... command)
command
array, in the same order. It is not checked whether
command corresponds to a valid operating system
command.command - A string array containing the program and its argumentspublic void setCaptureOutput(boolean captureOutput)
Default value is false, unless log level has been set to the TRACE level.
captureOutput - true to capture, false to ignore command outputpublic boolean isCaptureOutput()
public void setName(java.lang.String name)
name - a short string identifying the purpose of this Executor eg : "MyFeature"public java.lang.String getName()
public void setTimeout(long timeout)
DEFAULT_TIMEOUTtimeout - a duration in millisecond, 0 a negative value ofpublic long getTimeout()
If 0 was specified for timeout value, the default timeout is applied and this methods return the duration being applied
public ProcessExecutor.ProcessExecutionResult execute()
public static java.lang.String[] splitCommandLine(java.lang.String cmdLine)
Ensure any arguments enclosed in double quotes are kept as is.
cmdLine - the command line to splitCopyright © 2001-2019 Jalios SA. All Rights Reserved.