public class GenericProcessConsole
extends java.lang.Object
implements java.lang.Runnable
debug(String)
so they will not block.
By default, all System.out and System.err will go thru the debug() method.
Users can change this behavior by overriding the debug() method and also by turning off
the output of either or both of the streams via setShowOutStream(boolean)
and
setShowErrStream(boolean)
.
The class also attempts to see "unhandled exceptions" and store them in the exceptions Vector.
Normal usage might be something like below:
Process process = runtime.exec(procstr); GenericProcessConsole console = new GenericProcessConsole(process); Thread athread = new Thread(console); athread.start(); //we can wait until process is finished try{ athread.join();}catch(InterruptedException x){;} console.shutdown();//precautionThis class contains no extended SAFS dependencies and can be readily packaged and distributed for non-SAFS installations.
Modifier and Type | Field and Description |
---|---|
protected java.io.BufferedReader |
err |
static java.lang.String |
ERR_PREFIX
"ERR: "
|
protected java.util.Vector |
exceptions |
protected boolean |
exited
Returns true if the process we are capturing has exited.
|
protected int |
exitValue
Returns the exitValue returned from the underlying process.
|
protected java.io.BufferedWriter |
in |
protected java.io.BufferedReader |
out |
static java.lang.String |
OUT_PREFIX
"OUT: "
|
protected java.lang.Process |
process |
protected boolean |
showErrStream
set false to stop a copy of error stream data going to the debug sink.
|
protected boolean |
showOutStream
set false to stop a copy of output stream data going to the debug sink.
|
(package private) boolean |
shutdown |
Constructor and Description |
---|
GenericProcessConsole(java.lang.Process process)
Default (and only) public constructor for GenericProcessConsole.
|
GenericProcessConsole(java.lang.Process process,
boolean debug2Console) |
Modifier and Type | Method and Description |
---|---|
protected void |
_initialize(java.lang.Process process) |
protected void |
debug(java.lang.String message)
Writes to System.out .
|
java.util.Vector |
getExceptions() |
int |
getExceptionsCount() |
int |
getExitValue()
Get the process exitValue.
|
boolean |
isExited()
Returns true if the process we are capturing has exited.
|
void |
run()
Continuously monitors the process out and err streams routing them to the local
process System.out and System.err.
|
void |
setShowErrStream(boolean showErr)
set true to have the error stream copied to the active debug sink
|
void |
setShowOutStream(boolean showOut)
set true to have the output stream copied to the active debug sink
|
void |
shutdown()
Call to set the shutdown flag to true to stop the running console thread.
|
protected java.lang.Process process
protected java.io.BufferedReader out
protected java.io.BufferedReader err
protected java.io.BufferedWriter in
protected java.util.Vector exceptions
boolean shutdown
protected boolean showOutStream
protected boolean showErrStream
public static final java.lang.String OUT_PREFIX
public static final java.lang.String ERR_PREFIX
protected int exitValue
protected boolean exited
public GenericProcessConsole(java.lang.Process process)
public GenericProcessConsole(java.lang.Process process, boolean debug2Console)
protected void _initialize(java.lang.Process process)
public int getExitValue() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if process is still running.public boolean isExited()
protected void debug(java.lang.String message)
message
- public void setShowOutStream(boolean showOut)
public void setShowErrStream(boolean showErr)
public void shutdown()
public java.util.Vector getExceptions()
public int getExceptionsCount()
public void run()
run
in interface java.lang.Runnable
getExceptions()
,
shutdown()
Copyright © SAS Institute. All Rights Reserved.