public class DefaultProcessExecutor extends Object implements ProcessExecutor
Process
and blocks until it is finished.ProcessExecutor.LaunchedProcess, ProcessExecutor.LaunchedProcessImpl, ProcessExecutor.Option, ProcessExecutor.Result
Modifier | Constructor and Description |
---|---|
|
DefaultProcessExecutor(Console console)
Creates a new
DefaultProcessExecutor with the specified parameters used for writing the
output of the process. |
protected |
DefaultProcessExecutor(PrintStream stdOutStream,
PrintStream stdErrStream,
Ansi ansi,
ProcessHelper processHelper,
ProcessRegistry processRegistry) |
public DefaultProcessExecutor(Console console)
DefaultProcessExecutor
with the specified parameters used for writing the
output of the process.protected DefaultProcessExecutor(PrintStream stdOutStream, PrintStream stdErrStream, Ansi ansi, ProcessHelper processHelper, ProcessRegistry processRegistry)
public ProcessExecutor cloneWithOutputStreams(PrintStream newStdOutStream, PrintStream newStdErrStream)
ProcessExecutor
cloneWithOutputStreams
in interface ProcessExecutor
public ProcessExecutor.Result launchAndExecute(ProcessExecutorParams params) throws InterruptedException, IOException
ProcessExecutor
ProcessExecutor.launchAndExecute(ProcessExecutorParams, Set, Optional, Optional,
Optional)
with boolean values set to false
and optional values set to absent.launchAndExecute
in interface ProcessExecutor
InterruptedException
IOException
public ProcessExecutor.Result launchAndExecute(ProcessExecutorParams params, com.google.common.collect.ImmutableMap<String,String> context) throws InterruptedException, IOException
launchAndExecute
in interface ProcessExecutor
InterruptedException
IOException
public ProcessExecutor.Result launchAndExecute(ProcessExecutorParams params, Set<ProcessExecutor.Option> options, Optional<String> stdin, Optional<Long> timeOutMs, Optional<java.util.function.Consumer<Process>> timeOutHandler) throws InterruptedException, IOException
ProcessExecutor
params
.
If options
contains ProcessExecutor.Option.PRINT_STD_OUT
, then the stdout of the process
will be written directly to the stdout passed to the constructor of this executor. Otherwise,
the stdout of the process will be made available via ProcessExecutor.Result.getStdout()
.
If options
contains ProcessExecutor.Option.PRINT_STD_ERR
, then the stderr of the process
will be written directly to the stderr passed to the constructor of this executor. Otherwise,
the stderr of the process will be made available via ProcessExecutor.Result.getStderr()
.
launchAndExecute
in interface ProcessExecutor
InterruptedException
IOException
public ProcessExecutor.Result launchAndExecute(ProcessExecutorParams params, com.google.common.collect.ImmutableMap<String,String> context, Set<ProcessExecutor.Option> options, Optional<String> stdin, Optional<Long> timeOutMs, Optional<java.util.function.Consumer<Process>> timeOutHandler) throws InterruptedException, IOException
launchAndExecute
in interface ProcessExecutor
InterruptedException
IOException
public ProcessExecutor.LaunchedProcess launchProcess(ProcessExecutorParams params) throws IOException
ProcessExecutor
Process
given ProcessExecutorParams
.launchProcess
in interface ProcessExecutor
IOException
public ProcessExecutor.LaunchedProcess launchProcess(ProcessExecutorParams params, com.google.common.collect.ImmutableMap<String,String> context) throws IOException
launchProcess
in interface ProcessExecutor
IOException
public void destroyLaunchedProcess(ProcessExecutor.LaunchedProcess launchedProcess)
ProcessExecutor
ProcessExecutor.launchProcess(ProcessExecutorParams)
.destroyLaunchedProcess
in interface ProcessExecutor
public ProcessExecutor.Result waitForLaunchedProcess(ProcessExecutor.LaunchedProcess launchedProcess) throws InterruptedException
ProcessExecutor
ProcessExecutor.launchProcess(ProcessExecutorParams)
to exit, then returns the exit code of the process.
After this method returns, the launchedProcess
can no longer be passed to any
methods of this object.
waitForLaunchedProcess
in interface ProcessExecutor
InterruptedException
public ProcessExecutor.Result waitForLaunchedProcessWithTimeout(ProcessExecutor.LaunchedProcess launchedProcess, long millis, Optional<java.util.function.Consumer<Process>> timeOutHandler) throws InterruptedException
ProcessExecutor
ProcessExecutor.waitForLaunchedProcess(LaunchedProcess)
but with a timeout in milliseconds.waitForLaunchedProcessWithTimeout
in interface ProcessExecutor
InterruptedException
public ProcessExecutor.Result execute(ProcessExecutor.LaunchedProcess launchedProcess, Set<ProcessExecutor.Option> options, Optional<String> stdin, Optional<Long> timeOutMs, Optional<java.util.function.Consumer<Process>> timeOutHandler) throws InterruptedException
If options
contains Option#PRINT_STD_OUT
, then the stdout of the process
will be written directly to the stdout passed to the constructor of this executor. Otherwise,
the stdout of the process will be made available via Result#getStdout()
.
If options
contains Option#PRINT_STD_ERR
, then the stderr of the process
will be written directly to the stderr passed to the constructor of this executor. Otherwise,
the stderr of the process will be made available via Result#getStderr()
.
timeOutHandler
- If present, this method will be called before the process is killed.InterruptedException