|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectgate.util.ProcessManager
public class ProcessManager
Class that supports running an external process and either silently consuming its standard output and error streams, or copying them to Java's stdout and stderr. This implementation reads the output and error streams in separate threads, but tries to reuse these threads from one external call to the next, unlike other approaches I've seen (which all spawn a pair of new threads for every external call). As a result, instances of this class are not thread safe. You must use a different instance of ProcessManager in each thread that you use to run external processes.
| Nested Class Summary | |
|---|---|
private class |
ProcessManager.StreamGobbler
Thread body that takes a stream and either consumes it silently or echoes it to another stream. |
| Field Summary | |
|---|---|
private static boolean |
DEBUG
Debug flag. |
private ProcessManager.StreamGobbler |
stderr
StreamGobbler thread for standard error. |
private ProcessManager.StreamGobbler |
stdout
StreamGobbler thread for standard output. |
| Constructor Summary | |
|---|---|
ProcessManager()
Construct a ProcessManager object and start the gobbler threads. |
|
| Method Summary | |
|---|---|
int |
runProcess(String[] argv,
boolean dumpOutput)
Run the given external process. |
int |
runProcess(String[] argv,
OutputStream out,
OutputStream err)
Run the given external process. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final boolean DEBUG
private ProcessManager.StreamGobbler stdout
private ProcessManager.StreamGobbler stderr
| Constructor Detail |
|---|
public ProcessManager()
| Method Detail |
|---|
public int runProcess(String[] argv,
boolean dumpOutput)
throws IOException
argv - the process command line, suitable for passing to
Runtime.exec.dumpOutput - should we copy the process output and error streams to
the Java output and error streams or just consume them silently?
IOException
public int runProcess(String[] argv,
OutputStream out,
OutputStream err)
throws IOException
argv - the process command line, suitable for passing to
Runtime.exec.dumpOutput - should we copy the process output and error streams to
the Java output and error streams or just consume them silently?
IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||