public class ProcBuilder extends Object
| Constructor and Description |
|---|
ProcBuilder(String command,
String... args)
Creates a new ProcBuilder
|
| Modifier and Type | Method and Description |
|---|---|
static String |
filter(String input,
String cmd,
String... args)
Static helper to filter a string through a process
|
ProcBuilder |
ignoreExitStatus()
Ignore the error status returned from this command
|
ProcResult |
run()
Spawn the actual execution.
|
static String |
run(String cmd,
String... args)
Static helper to run a process
|
ProcBuilder |
withArg(String arg)
Adds another argument
|
ProcBuilder |
withArgs(String... args)
Add multiple args
|
ProcBuilder |
withExitStatuses(int[] exitstatuses)
Deprecated.
Please use the variants with a set or vargs parameters
|
ProcBuilder |
withExpectedExitStatuses(int... expectedExitStatuses)
Define the valid exit status codes for the command
Convenience method taking varargs.
|
ProcBuilder |
withExpectedExitStatuses(Set<Integer> expectedExitStatuses)
Define the valid exit status codes for the command
|
ProcBuilder |
withInputStream(InputStream stdin)
Take the input for the program from a given InputStream
|
ProcBuilder |
withNoTimeout()
Disable timeout for the operation.
|
ProcBuilder |
withOutputConsumer(StreamConsumer outputConsumer)
Process the standard output with the given consumer object
|
ProcBuilder |
withOutputStream(OutputStream stdout)
Redirecting the standard output.
|
ProcBuilder |
withTimeoutMillis(long timeoutMillis)
Specify a timeout for the operation.
|
ProcBuilder |
withVar(String var,
String value)
Add a variable to the processes environment
|
ProcBuilder |
withWorkingDirectory(File directory)
Override the wokring directory
|
public ProcBuilder withArg(String arg)
arg - to addpublic ProcBuilder withOutputStream(OutputStream stdout)
stdout - stream to redirect the output to. \public ProcBuilder withTimeoutMillis(long timeoutMillis)
timeoutMillis - time that the process gets to runpublic ProcBuilder withNoTimeout()
public ProcBuilder withInputStream(InputStream stdin)
stdin - stream to read the input frompublic ProcBuilder withWorkingDirectory(File directory)
directory - the working directory for the processpublic ProcBuilder withArgs(String... args)
args - the arguments addpublic ProcBuilder withExitStatuses(int[] exitstatuses)
exitstatuses - array containing the exit codes that are validpublic ProcBuilder withExpectedExitStatuses(Set<Integer> expectedExitStatuses)
expectedExitStatuses - array containing the exit codes that are validpublic ProcBuilder withExpectedExitStatuses(int... expectedExitStatuses)
expectedExitStatuses - varargs parameter containing the exit codes that are validpublic ProcBuilder ignoreExitStatus()
public ProcResult run() throws StartupException, TimeoutException, ExternalProcessFailureException
StartupException - if the process can't be startedTimeoutException - if the timeout kicked inExternalProcessFailureException - if the external process returned a non-null exit valuepublic static String run(String cmd, String... args)
cmd - the commandargs - the argumentsStartupException - if the process can't be startedTimeoutException - if the timeout kicked inExternalProcessFailureException - if the external process returned a non-null exit valuepublic static String filter(String input, String cmd, String... args)
input - the input to be fed into the processcmd - the commandargs - the argumentsStartupException - if the process can't be startedTimeoutException - if the timeout kicked inExternalProcessFailureException - if the external process returned a non-null exit valuepublic ProcBuilder withVar(String var, String value)
var - variable namevalue - the value to be passed inpublic ProcBuilder withOutputConsumer(StreamConsumer outputConsumer)
outputConsumer - an object that defines how to process the standard output streamCopyright © 2017. All rights reserved.