java.lang.Object
org.itsallcode.process.SimpleProcess<T>
- Type Parameters:
T
- type of stdout and stderr, e.g.String
.
Provides control over native processes.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
Kill the process.void
Kill the process forcibly.int
Get the exit value of the process.Get the standard error of the process.Get the standard output of the process.boolean
isAlive()
Check wether the process is alive.long
pid()
Get the process ID.void
Wait until the process terminates successfully with exit code0
.int
Wait until the process has terminated.void
waitForTermination
(int expectedExitCode) Wait until the process terminates successfully with the given exit code.void
waitForTermination
(Duration timeout) Wait until the process terminates with the given timeout.
-
Method Details
-
waitForTermination
Wait until the process has terminated.- Returns:
- exit code
- See Also:
-
waitForSuccessfulTermination
Wait until the process terminates successfully with exit code0
.- Throws:
IllegalStateException
- if exit code is not equal to0
.- See Also:
-
waitForTermination
Wait until the process terminates successfully with the given exit code.- Parameters:
expectedExitCode
- expected exit code- Throws:
IllegalStateException
- if exit code is not equal to the given expected exit code.- See Also:
-
waitForTermination
Wait until the process terminates with the given timeout.- Parameters:
timeout
- maximum time to wait for the termination- Throws:
IllegalStateException
- if process does not exit within the given timeout.- See Also:
-
getStdOut
Get the standard output of the process.- Returns:
- standard output
-
getStdErr
Get the standard error of the process.- Returns:
- standard error
-
isAlive
Check wether the process is alive.- Returns:
true
if the process has not yet terminated- See Also:
-
exitValue
Get the exit value of the process.- Returns:
- exit value
- See Also:
-
pid
Get the process ID.- Returns:
- process ID
- See Also:
-
destroy
Kill the process.- See Also:
-
destroyForcibly
Kill the process forcibly.- See Also:
-