Class ProcessManager
java.lang.Object
com.sun.enterprise.universal.process.ProcessManager
Extension of
ProcessBuilder that provides additional functionality to manage input and
output of the process.- Author:
- bnevins 2005, Ondro Mihalyi, David Matejcek
-
Constructor Summary
ConstructorsConstructorDescriptionProcessManager(String... cmds) Creates a new ProcessManager with the specified command line.ProcessManager(List<String> cmdline) Creates a new ProcessManager with the specified command line. -
Method Summary
Modifier and TypeMethodDescriptionintexecute()Executes the command and waits for it to finish while reading its output.Returns the standard error output of the process.Returns the standard output of the process.voidsetEcho(boolean newEcho) Should the output of the process be echoed to stdout?voidsetEnvironment(String name, String value) Sets an environment variable for the process.voidsetStdinLines(List<String> list) Sets the input lines for the process.voidsetTextToWaitFor(String textToWaitFor) If not null, should wait until this text is found in standard output instead of waiting until the process terminatesvoidsetTimeout(int millis) Sets the timeout for the process execution or for the detected text in the output.voidsetTimeout(int millis, boolean forceExit) Sets the timeout for the process execution or for the detected text in the output.voidsetWorkingDir(File directory) Sets the working directory for the process.toString()
-
Constructor Details
-
ProcessManager
Creates a new ProcessManager with the specified command line.- Parameters:
cmds- must not be null or empty.
-
ProcessManager
Creates a new ProcessManager with the specified command line.- Parameters:
cmdline- must not be null or empty.
-
-
Method Details
-
toString
-
setTimeout
public void setTimeout(int millis) Sets the timeout for the process execution or for the detected text in the output. If the process does not finish within the specified timeout, it will be terminated.- Parameters:
millis- the timeout in milliseconds, must not be negative
-
setTimeout
public void setTimeout(int millis, boolean forceExit) Sets the timeout for the process execution or for the detected text in the output. If the process does not finish within the specified timeout, it can be terminated automatically.- Parameters:
millis- the timeout in milliseconds, must not be negativeforceExit- if true, the process will be forcibly terminated if it does not finish within the timeout
-
setEnvironment
Sets an environment variable for the process.- Parameters:
name- the name of the environment variable, must not be nullvalue- the value of the environment variable, can be null
-
setWorkingDir
Sets the working directory for the process.- Parameters:
directory- the working directory, must not be null
-
setStdinLines
Sets the input lines for the process. The lines will be written to the process's standard input.- Parameters:
list- a list of strings to be written to the process's standard input, can be null or empty
-
setEcho
public void setEcho(boolean newEcho) Should the output of the process be echoed to stdout?- Parameters:
newEcho-
-
setTextToWaitFor
If not null, should wait until this text is found in standard output instead of waiting until the process terminates- Parameters:
textToWaitFor-
-
getStdout
Returns the standard output of the process. If the textToWaitFor was set, the output will contain all lines read from the process until the textToWaitFor was found.- Returns:
- the standard output of the process
-
getStderr
Returns the standard error output of the process. If the textToWaitFor was set, the output will contain all lines read from the process until the textToWaitFor was found.- Returns:
- the standard error output of the process
-
execute
Executes the command and waits for it to finish while reading its output.- Returns:
- exit code. Can be overridden internally when we are waiting for a specific text in output and we succeeded despite the process failed or even did not finish. If we have found the output, we don't kill the process.
- Throws:
ProcessManagerException
-