|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.jalios.jcms.tools.ProcessExecutor
public class ProcessExecutor
Helper class to execute native operating system process.
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).
| Nested Class Summary | |
|---|---|
class |
ProcessExecutor.ProcessExecutionResult
Holds process execution result. |
| Field Summary | |
|---|---|
static long |
DEFAULT_TIMEOUT
Default value in milliseconds for the maximum execution time of a Process before is destroyed : 600000L |
| Constructor Summary | |
|---|---|
ProcessExecutor(List<String> command)
Constructs a process executor with the specified operating system program and arguments. |
|
ProcessExecutor(String... command)
Constructs a process executor with the specified operating system program and arguments. |
|
| Method Summary | |
|---|---|
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). |
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(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 String[] |
splitCommandLine(String cmdLine)
Split the specified command line String into a String array. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final long DEFAULT_TIMEOUT
| Constructor Detail |
|---|
public ProcessExecutor(List<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 arguments
NullPointerException - If the argument is nullpublic ProcessExecutor(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 arguments| Method Detail |
|---|
public 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(String name)
name - a short string identifying the purpose of this Executor eg : "MyFeature"public String getName()
public void setTimeout(long timeout)
DEFAULT_TIMEOUT
timeout - 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 String[] splitCommandLine(String cmdLine)
Ensure any arguments enclosed in double quotes are kept as is.
cmdLine - the command line to split
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||