gate.util
Class ProcessManager

java.lang.Object
  extended by gate.util.ProcessManager

public class ProcessManager
extends Object

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.


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, File dir, OutputStream out, OutputStream err)
          Run the given external process.
 int runProcess(String[] argv, OutputStream out, OutputStream err)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProcessManager

public ProcessManager()
Construct a ProcessManager object and start the gobbler threads.

Method Detail

runProcess

public int runProcess(String[] argv,
                      boolean dumpOutput)
               throws IOException
Run the given external process. If an exception results from starting the process, or while reading the output from the process, it will be thrown. Otherwise, the exit value from the process is returned.

Parameters:
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?
Throws:
IOException

runProcess

public int runProcess(String[] argv,
                      OutputStream out,
                      OutputStream err)
               throws IOException
Throws:
IOException

runProcess

public int runProcess(String[] argv,
                      File dir,
                      OutputStream out,
                      OutputStream err)
               throws IOException
Run the given external process. If an exception results from starting the process, or while reading the output from the process, it will be thrown. Otherwise, the exit value from the process is returned.

Parameters:
argv - the process command line, suitable for passing to Runtime.exec.
Throws:
IOException