|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.knowceans.util.ExternalProcess
public class ExternalProcess
Class to start an external process and connect the three standard streams.
The process can be run using the constructor, then optionally connection its
output streams stdout and stdin with Java InputStreams using
getStreamFromStdout and getStreamFromStderr, then calling waitfor() to wait
until the process has finished. Any stdin of the external program can be
assigned via the last arg to the constructor; if stdin should be from a
String, use StringBufferInputStream.
If getStreamFromStdout and getStreamFromStderr are used, they should be
buffered and run in a separate thread if possible. If they are not explicitly
requested by the caller, internal threads are used that collect the output in
a buffer that can be requested from the caller class via getCompleteStdout
and getCompleteStderr. Additionally, the threads display the process output
in Java's stdout and stderr.
TODO: stdin does not work yet.
Constructor Summary | |
---|---|
ExternalProcess(java.lang.String command,
java.lang.String[] options,
java.lang.String[] environment,
java.io.InputStream stdin,
java.io.File workDir)
Initialise the external program. |
Method Summary | |
---|---|
java.lang.String |
getCompleteStderr()
get output from the stderr buffer thread. |
java.lang.String |
getCompleteStdout()
get output from the stdout buffer thread. |
java.io.InputStream |
getStreamFromStderr()
Stderr from the process is processed by the user. |
java.io.InputStream |
getStreamFromStdout()
Stdout from the process is processed by the user. |
static void |
main(java.lang.String[] args)
test method to run an external program |
int |
waitFor()
should be called after the process has been started (using the constructor) |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ExternalProcess(java.lang.String command, java.lang.String[] options, java.lang.String[] environment, java.io.InputStream stdin, java.io.File workDir) throws java.lang.Exception
command
- required system-visible commandoptions
- optional, set null or zero-length if unwantedenvironment
- optional, set null or zero-length if unwantedstding
- stream to connect to stdin of the process, null if not wantedworkDir
- to run the process in
java.lang.Exception
Method Detail |
---|
public int waitFor() throws java.lang.InterruptedException
java.lang.InterruptedException
public java.io.InputStream getStreamFromStdout()
public java.io.InputStream getStreamFromStderr()
public java.lang.String getCompleteStdout()
public java.lang.String getCompleteStderr()
public static void main(java.lang.String[] args)
args
-
java.lang.Exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |