- java.lang.Object
-
- de.carne.test.swt.platform.ProcessRunner
-
public final class ProcessRunner extends java.lang.ObjectUtility class providing platform command execution support.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classProcessRunner.StatusThe status of a ProcessRunner instance.
-
Constructor Summary
Constructors Constructor Description ProcessRunner(java.lang.String... command)Constructs a new ProcessRunner instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckStatus()Checks the status of the last run() invocation and throws an I/O exception in case an error occurred or if the process' exit status is not 0.intexitValue()Gets the process exit value of the last run() invocation.java.lang.Stringoutput()Gets the process output captured during the last run() invocation.ProcessRunner.Statusrun()Runs the command and waits until either the process completes or an error occurs.java.util.Optional<java.io.IOException>statusException()Gets the optional IOException caught during the last run() invocation.java.lang.StringtoString()ProcessRunnerwithCaptureOutput(boolean capture)Sets the capture-output option for process execution.ProcessRunnerwithTimeout(long timeout)Sets the timeout (in milliseconds) to wait for process completion.
-
-
-
Constructor Detail
-
ProcessRunner
public ProcessRunner(java.lang.String... command)
Constructs a new ProcessRunner instance.- Parameters:
command- the command line to run.
-
-
Method Detail
-
withTimeout
public ProcessRunner withTimeout(long timeout)
Sets the timeout (in milliseconds) to wait for process completion.- Parameters:
timeout- the timeout to use.- Returns:
- the updated ProcessRunner instance.
-
withCaptureOutput
public ProcessRunner withCaptureOutput(boolean capture)
Sets the capture-output option for process execution.- Parameters:
capture- whether to capture the running's process output (true) or not (false).- Returns:
- the updated ProcessRunner instance.
-
run
public ProcessRunner.Status run()
Runs the command and waits until either the process completes or an error occurs.- Returns:
- the new status of this ProcessRunner instance.
-
checkStatus
public void checkStatus() throws java.io.IOExceptionChecks the status of the last run() invocation and throws an I/O exception in case an error occurred or if the process' exit status is not 0.- Throws:
java.io.IOException- if an error occurred during
-
statusException
public java.util.Optional<java.io.IOException> statusException()
Gets the optional IOException caught during the last run() invocation.- Returns:
- the optional IOException caught during the last run() invocation.
-
exitValue
public int exitValue()
Gets the process exit value of the last run() invocation.- Returns:
- the process exit value of the last run() invocation.
-
output
public java.lang.String output()
Gets the process output captured during the last run() invocation.- Returns:
- the process output captured during the last run() invocation.
- See Also:
withCaptureOutput(boolean)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-