@ParametersAreNonnullByDefault public final class ProcessUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static Process |
buildProcess(String[] commandLine,
Reader input,
Consumer<String> stdOutConsumer,
Consumer<String> stdErrConsumer)
Builds and starts a system process for the given set of command line arguments.
|
static int |
invokeProcess(String[] commandLine)
Runs the given set of command line arguments as a system process and returns the exit value of the spawned
process.
|
static int |
invokeProcess(String[] commandLine,
Consumer<String> consumer)
Runs the given set of command line arguments as a system process and returns the exit value of the spawned
process.
|
static int |
invokeProcess(String[] commandLine,
Reader input)
Runs the given set of command line arguments as a system process and returns the exit value of the spawned
process.
|
static int |
invokeProcess(String[] commandLine,
Reader input,
Consumer<String> consumer)
Runs the given set of command line arguments as a system process and returns the exit value of the spawned
process.
|
public static int invokeProcess(String[] commandLine) throws IOException, InterruptedException
commandLine - the list of command line arguments to runIOException - if an exception occurred while reading the process' outputsInterruptedException - if an exception occurred during process exceptionpublic static int invokeProcess(String[] commandLine, Reader input) throws IOException, InterruptedException
commandLine - the list of command line arguments to runinput - the input passed to the programIOException - if an exception occurred while reading the process' outputs, or writing the process' inputsInterruptedException - if an exception occurred during process exceptionpublic static int invokeProcess(String[] commandLine, Consumer<String> consumer) throws IOException, InterruptedException
consumer.commandLine - the list of command line arguments to runconsumer - the consumer for the program's outputIOException - if an exception occurred while reading the process' outputsInterruptedException - if an exception occurred during process exceptionpublic static int invokeProcess(String[] commandLine, Reader input, Consumer<String> consumer) throws IOException, InterruptedException
consumer.commandLine - the list of command line arguments to runinput - the input passed to the programconsumer - the consumer for the program's outputIOException - if an exception occurred while reading the process' outputs, or writing the process' inputsInterruptedException - if an exception occurred during process exceptionpublic static Process buildProcess(String[] commandLine, @Nullable Reader input, @Nullable Consumer<String> stdOutConsumer, @Nullable Consumer<String> stdErrConsumer) throws IOException
The consumers for the process' outputs run in separate threads, preventing potential deadlock scenarios where
client code waits for the process' termination (e.g. Process.waitFor()) which is blocked by full system
buffers.
commandLine - the list of command line arguments to runinput - the input passed to the program, maybe be null if the process expects no inputstdOutConsumer - the consumer for the programs outputstdErrConsumer - the consumer for the programs outputIOException - if an exception occurred while reading the process outputsCopyright © 2019. All rights reserved.