public class ProcessCapture extends GenericProcessCapture
This subclass writes to org.safs.Log (SAFS Debug Log) instead of to System.out
Normal usage might be something like below:
Process process = runtime.exec(procstr);
ProcessCapture console = new ProcessCapture(process);
Thread athread = new Thread(console);
athread.start();
//we can wait until process is finished
try{ athread.join();}catch(InterruptedException x){;}
console.shutdown();//precaution
Vector data = console.getData();
Alternatively, we can autostart the capture thread. We don't have to wait for
it to end if we don't want to. The autostarted thread can be acquired, though:
Process process = runtime.exec(procstr);
ProcessCapture console = new ProcessCapture(process, null, true, true);
//we can wait until process is finished if we want
try{ console.thread.join();}catch(InterruptedException x){;}
Vector data = console.getData();
console.shutdown();//precautionary force shutdown
Data for the Error and Output streams is captured into the single Vector storage.
The Error stream data is prefixed with the ERR_PREFIX, while the Output data is
prefixed with the OUT_PREFIX.
In the latter example the out and err streams will also appear in any active debug() sink/console.
data, monitor, threaderr, ERR_PREFIX, exceptions, exited, exitValue, in, out, OUT_PREFIX, process, showErrStream, showOutStream, shutdown| Constructor and Description |
|---|
ProcessCapture(java.lang.Process process)
Default Constructor for ProcessCapture.
|
ProcessCapture(java.lang.Process process,
java.lang.String monitor,
boolean autostart)
Alternative constructor suggesting the IO thread should remain open as long as
a secondary process/pid remains running.
|
ProcessCapture(java.lang.Process process,
java.lang.String monitor,
boolean autostart,
boolean debug2console)
Alternative constructor suggesting the IO thread should remain open as long as
a secondary process/pid remains running.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
debug(java.lang.String message)
Writes to
Log.debug(Object)--the SAFS Debug Log. |
getData, getDataLineCount, run, waitOutput_initialize, getExceptions, getExceptionsCount, getExitValue, isExited, setShowErrStream, setShowOutStream, shutdownpublic ProcessCapture(java.lang.Process process)
process - to capture IO in, out, and err streams.GenericProcessConsole.setShowOutStream(boolean),
GenericProcessConsole.setShowErrStream(boolean)public ProcessCapture(java.lang.Process process,
java.lang.String monitor,
boolean autostart)
process - -- to capture IO in, out, and err streams.monitor - -- optional secondary process name or pid to monitor for continued
IO output.autostart - -- true if we should automatically start the separate capture thread.GenericProcessConsole.setShowOutStream(boolean),
GenericProcessConsole.setShowErrStream(boolean)public ProcessCapture(java.lang.Process process,
java.lang.String monitor,
boolean autostart,
boolean debug2console)
process - -- to capture IO in, out, and err streams.monitor - -- optional secondary process name or pid to monitor for continued
IO output.autostart - -- true if we should automatically start the separate capture thread.debug2console - -- true if out and err streams should appear in the debug sink/console.
The streams do NOT appear in the debug sink/console by default.protected void debug(java.lang.String message)
Log.debug(Object)--the SAFS Debug Log.
Subclasses should override to log to alternate sinks.debug in class GenericProcessConsolemessage - Copyright © SAS Institute. All Rights Reserved.