It's implemented as a wrapper of {@link ProcessBuilder} complementing it with additional features such as:
Handling process streams (copied from Commons Exec library).
Destroying process on VM exit (copied from Commons Exec library).
Checking process exit code.
Setting a timeout for running the process and automatically stopping it in case of timeout.
Either waiting for the process to finish ( {@link #execute()}) or returning a {@link Future} ({@link #start()}.
Reading the process output stream into a buffer ( {@link #readOutput(boolean)}, {@link ProcessResult}).
The default configuration for executing a process is following:
Process is not automatically destroyed on VM exit.
Error stream is redirected to its output stream. Use {@link #redirectErrorStream(boolean)} to override it.
Output stream is pumped to a {@link NullOutputStream}, Use {@link #streams(ExecuteStreamHandler)}, {@link #redirectOutput(OutputStream)}, or any of the redirectOutputAs* methods.to override it.
Any exit code is allowed. Use {@link #exitValues(Integer)} to override it.
In case of timeout or cancellation {@link Process#destroy()} is invoked.
public void testJavaVersionLogInfoAndOutput() throws Exception {
// Just expect no errors - don't check the log file itself
ProcessResult result = new ProcessExecutor().command("java", "-version").redirectOutput(Slf4jStream.of("testJavaVersionLogInfoAndOutput").asInfo()).readOutput(true).execute();
public void testJavaVersionLogInfoAndOutputFuture() throws Exception {
// Just expect no errors - don't check the log file itself
ProcessResult result = new ProcessExecutor().command("java", "-version").redirectOutput(Slf4jStream.of("testJavaVersionLogInfoAndOutputFuture").asInfo()).readOutput(true).start().getFuture().get();
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.