Some commands may block until you start reading their stdout or stderr. This may be problem when you just want to run a command ignoring its output. Use flush methods in that case.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionint
await()
Waits for process to complete and returns code safely wrapping all checked exceptions to RuntimeException.code()
void
Java original methodProcess.destroyForcibly()
does not destroy child processes.forwardOutputAsync
(boolean ignore) Consumes stdout and stderr by forwarding them to System.out and System.err respectively.forwardStderrAsync
(boolean ignore) Consumes stderr stream by forwarding it to System.err This call is async.forwardStdoutAsync
(boolean ignore) Consumes stdout stream by forwarding it to System.out.outputAsync
(boolean ignore) CombinesstdoutAsync(boolean)
andstderrAsync(boolean)
into one methodprocess()
stderr()
Returns standard error output as a string.After you consume this stream it will not be longer valid.stderrAsync
(boolean ignore) Consumes stderr stream into internal buffer which later can be obtained throughstderr()
or ignores it.stderrAsync
(Consumer<String> consumer) Consumes stderr stream by forwarding it to consumer.Block until process finishes and then check its return code.stdout()
Returns standard output as a string.After you consume this stream it will not be longer valid.stdoutAsync
(boolean ignore) Consumes stdout stream into internal buffer which later can be obtained throughstdout()
or ignores it.stdoutAsync
(Consumer<String> consumer) Consumes stdout stream by forwarding it to consumer.
-
Constructor Details
-
Method Details
-
stdout
Returns standard output as a string. This call will consume stdout stream meaning that you can call it only once. If you want to call it multiple times make sure to callstdoutAsync(boolean)
orforwardStdoutAsync(boolean)
first.- Throws:
IllegalStateException
- if called more than once- See Also:
-
stdoutAsync
Consumes stdout stream into internal buffer which later can be obtained throughstdout()
or ignores it. This call is async.When process writes to stdout it may get blocked until somebody starts reading it. This methods starts reading immediately in background (so that process will not block) and preserves the output.
-
forwardStdoutAsync
Consumes stdout stream by forwarding it to System.out. This call is async.- Parameters:
ignore
- save forwarded output into internal buffer which later can be obtained throughstdout()
or ignore it
-
stdoutAsync
Consumes stdout stream by forwarding it to consumer. This call is async. -
stderr
Returns standard error output as a string. This call will consume stderr stream meaning that you can call it only once. If you want to call it multiple times make sure to callstderrAsync(boolean)
orforwardStderrAsync(boolean)
first.- Throws:
IllegalStateException
- if called more than once- See Also:
-
stderrThrow
Block until process finishes and then check its return code. If it is non 0 then throw an exception with data from stderr. -
stderrAsync
Consumes stderr stream into internal buffer which later can be obtained throughstderr()
or ignores it. This call is async.When process writes to stderr it may get blocked until somebody starts reading it. This methods starts reading immediately in background (so that process will not block) and preserves the output.
-
stderrAsync
Consumes stderr stream by forwarding it to consumer. This call is async. -
forwardStderrAsync
Consumes stderr stream by forwarding it to System.err This call is async.- Parameters:
ignore
- save forwarded stderr into internal buffer which later can be obtained throughstderr()
or ignore it
-
outputAsync
CombinesstdoutAsync(boolean)
andstderrAsync(boolean)
into one methodWhen process writes to stdout/stderr it may get blocked until somebody starts reading it. This methods starts reading both immediately in background (so that process will not block) and preserves the output.
- See Also:
-
forwardOutputAsync
Consumes stdout and stderr by forwarding them to System.out and System.err respectively. -
process
-
stdoutAsStream
After you consume this stream it will not be longer valid. -
stderrAsStream
After you consume this stream it will not be longer valid. -
code
- Returns:
- process return code
-
await
public int await()Waits for process to complete and returns code safely wrapping all checked exceptions to RuntimeException.Make sure to use
outputAsync(boolean)
method to ignore both output/stderr. -
destroyAllForcibly
public void destroyAllForcibly()Java original methodProcess.destroyForcibly()
does not destroy child processes. This method destroys all children processes including parent one.
-