public class ListeningProcessExecutor extends Object
ProcessBuilder
which provides an asynchronous callback interface to
notify the caller on a background thread when a process starts, performs I/O, or exits.
Unlike ProcessExecutor
, this does not automatically forward output to Console
formatted with ANSI escapes.
Modifier and Type | Class and Description |
---|---|
static interface |
ListeningProcessExecutor.LaunchedProcess
Represents a process which was launched by a
ListeningProcessExecutor . |
static interface |
ListeningProcessExecutor.ProcessListener
Callback API to notify the caller on a background thread when a process starts, exits, has
stdout or stderr bytes to read, or is ready to receive bytes on stdin.
|
Constructor and Description |
---|
ListeningProcessExecutor() |
Modifier and Type | Method and Description |
---|---|
void |
destroyProcess(ListeningProcessExecutor.LaunchedProcess process,
boolean force)
Destroys a process.
|
ListeningProcessExecutor.LaunchedProcess |
launchProcess(ProcessExecutorParams params,
ListeningProcessExecutor.ProcessListener listener)
Launches a process and asynchronously sends notifications to
listener on a background
thread when the process starts, has I/O, or exits. |
int |
waitForProcess(ListeningProcessExecutor.LaunchedProcess process)
Blocks the calling thread until the process exits.
|
int |
waitForProcess(ListeningProcessExecutor.LaunchedProcess process,
long timeout,
TimeUnit timeUnit)
Blocks the calling thread until either the process exits or the timeout expires, whichever is
first.
|
public ListeningProcessExecutor.LaunchedProcess launchProcess(ProcessExecutorParams params, ListeningProcessExecutor.ProcessListener listener) throws IOException
listener
on a background
thread when the process starts, has I/O, or exits.IOException
public int waitForProcess(ListeningProcessExecutor.LaunchedProcess process, long timeout, TimeUnit timeUnit) throws InterruptedException
Integer.MIN_VALUE
if the timeout expired or the process failed to start, or the
exit code of the process otherwise.InterruptedException
public int waitForProcess(ListeningProcessExecutor.LaunchedProcess process) throws InterruptedException, IOException
IOException
- if the process failed to start.InterruptedException
public void destroyProcess(ListeningProcessExecutor.LaunchedProcess process, boolean force)
force
is true
, then forcibly destroys the process in a
way it cannot ignore.