Package com.peterphi.std.system.exec
Class BasicProcessTracker
java.lang.Object
com.peterphi.std.system.exec.BasicProcessTracker
A basic process tracker that does not touch stdout/stderr streams
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBasicProcessTracker(List<String> cmd, Process p, boolean combinedOutput) -
Method Summary
Modifier and TypeMethodDescriptionprotected Threadcopy(InputStream in, Writer out) protected Threaddiscard(InputStream in) voidIndicates that the output of this process should be discardedintexitCode()Returns the exit code of the application, assuming it has already terminated.protected voidfinished(int exitCode) booleanDetermines if the application has completed yetprotected booleanReturns true if the output of this process is still being readfinal voidkill()voidkill(boolean force) protected voidintWait an indefinite amount of time for the process to exitintwaitForExit(int expected) Wait an indefinite amount of time for the process to exit, expecting the return code to beexpected.intwaitForExit(Deadline deadline) Waits for the process to exit; this method blocks until the process has completed (at which point it returns the process exit code) or untildeadlinehas elapsed, at which point it returns Integer.MIN_VALUEintwaitForExit(Deadline deadline, int expected) Wait untildeadlinefor the process to exit, expecting the return code to beexpected.
-
Field Details
-
cmd
-
process
-
combinedOutput
protected final boolean combinedOutput -
finished
protected boolean finished -
exitCode
protected int exitCode
-
-
Constructor Details
-
BasicProcessTracker
-
-
Method Details
-
isStillReadingOutput
protected boolean isStillReadingOutput()Returns true if the output of this process is still being read- Returns:
- false if this instance is copying the stdout/stderr and they have been closed, otherwise true if we are still copying stdout/stderr. Always returns false if some external agent is handling the stdout/stderr streams.
-
discardOutput
public void discardOutput()Indicates that the output of this process should be discarded -
getProcess
-
kill
public final void kill() -
kill
public void kill(boolean force) -
isFinished
public boolean isFinished()Determines if the application has completed yet- Returns:
- true if the process has terminated, otherwise false
-
exitCode
Returns the exit code of the application, assuming it has already terminated. If the process has not yet terminated then an IllegalStateException will be thrown- Returns:
- the exit code of the process
- Throws:
IllegalStateException- if the process has not yet terminatedIllegalThreadStateException
-
waitForExit
public int waitForExit(int expected) Wait an indefinite amount of time for the process to exit, expecting the return code to beexpected. If the output is notexpectedthen a RuntimeException is thrown- Parameters:
expected- the expected return code- Returns:
- the exit code of the process
- Throws:
RuntimeException- if the return code was not what was expected
-
waitForExit
Wait untildeadlinefor the process to exit, expecting the return code to beexpected. If the output is notexpected(or if the operation times out) then a RuntimeException is thrown
In the event of a timeout the process is not terminated- Parameters:
deadline-expected-- Returns:
- the exit code of the process
- Throws:
RuntimeException- if a timeout occurrs or if the return code was not what was expected
-
waitForExit
public int waitForExit()Wait an indefinite amount of time for the process to exit- Returns:
- the exit code of the process
-
waitForExit
Waits for the process to exit; this method blocks until the process has completed (at which point it returns the process exit code) or untildeadlinehas elapsed, at which point it returns Integer.MIN_VALUE- Parameters:
deadline-- Returns:
- the exit code of the process
-
getStandardOutputStream
-
getStandardErrorStream
-
getStandardInputStream
-
finished
protected void finished(int exitCode) -
unexpectedFailure
-
copy
-
discard
-