Package org.apache.uima.pear.util
Class ProcessUtil.Runner
java.lang.Object
org.apache.uima.pear.util.ProcessUtil.Runner
- All Implemented Interfaces:
Runnable
- Enclosing class:
- ProcessUtil
The
ProcessUtil.Runner class allows collecting, printing and distributing console
output (stdout and stderr) of the specified Process without blocking the caller.
It allows adding standard stream listeners to receive messages printed to the console by
selected process.-
Constructor Summary
ConstructorsConstructorDescriptionConstructor that takes a givenProcessobject and assigns default process name.Constructor that takes a givenProcessobject and a given process name.Constructor that takes a givenProcessobject, a given process name, and a givenbooleanflag that enables/disables console printing. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a given object, implementing theStdStreamListenerinterface to the list of standard stream listeners.intvoidremoveListener(ProcessUtil.StdStreamListener listener) Removes a givenStdStreamListenerobject from the list of standard stream listeners.voidrun()Implements theRunnable.run()method, collecting and printing standard output or standard error messages during the process execution.intwaitFor()Allows the caller to wait for the completion of the process.intwaitFor(long timeout) Allows the caller to wait for the completion of the process, but no longer than a given timeout value.
-
Constructor Details
-
Runner
Constructor that takes a givenProcessobject and assigns default process name.- Parameters:
aProcess- The givenProcessobject.
-
Runner
Constructor that takes a givenProcessobject and a given process name.- Parameters:
aProcess- The givenProcessobject.procName- The given process name.
-
Runner
Constructor that takes a givenProcessobject, a given process name, and a givenbooleanflag that enables/disables console printing. If the given process name isnull, the default process name is assigned.- Parameters:
aProcess- The givenProcessobject.procName- The given process name.printToConsole-booleanflag that enables/disables console printing.
-
-
Method Details
-
addStreamListener
Adds a given object, implementing theStdStreamListenerinterface to the list of standard stream listeners. Sends to the new listener previously printed standard error and standard output messages.- Parameters:
listener- The given new standard stream listener.
-
getExitCode
public int getExitCode()- Returns:
- Process exit code after the process finishes, otherwise
Integer.MAX_VALUE.
-
getErrOutput
- Returns:
- Standard error messages collected during the process execution.
-
getProcess
-
getStdOutput
- Returns:
- Standard output messages collected during the process execution.
-
removeListener
Removes a givenStdStreamListenerobject from the list of standard stream listeners.- Parameters:
listener- The givenStdStreamListenerobject to be removed from the list.
-
run
public void run()Implements theRunnable.run()method, collecting and printing standard output or standard error messages during the process execution. -
waitFor
public int waitFor()Allows the caller to wait for the completion of the process.- Returns:
- Process exit code.
-
waitFor
public int waitFor(long timeout) Allows the caller to wait for the completion of the process, but no longer than a given timeout value.- Parameters:
timeout- The given timeout value (ms).- Returns:
- Process exit code or
Integer.MAX_VALUE, if the process has not finished yet.
-