to.etc.util
Class ProcessTools

java.lang.Object
  extended by to.etc.util.ProcessTools

public class ProcessTools
extends java.lang.Object

Helper code to spawn processes and capture their output.

Author:
Frits Jalvingh Created on Nov 25, 2010

Nested Class Summary
static class ProcessTools.StreamCopyThread
          This is used to async read strout and stderr streams from a process into another output stream.
static class ProcessTools.StreamReaderThread
          This is used to async read strout and stderr streams from a process...
 
Method Summary
static int dumpStreams(java.lang.Process pr, java.lang.Appendable iosb)
          Waits for completion of the command and collect data into the streams.
static int runProcess(java.lang.ProcessBuilder pb, java.lang.Appendable sb)
          Runs the process whose data is in the ProcessBuilder and captures the result with stdout and stderr merged.
static int runProcess(java.lang.ProcessBuilder pb, java.lang.Appendable outsb, java.lang.Appendable errsb)
          Runs the process whose data is in the ProcessBuilder and captures the result with stdout and stderr merged.
static int runProcess(java.lang.ProcessBuilder pb, java.io.OutputStream stdout, java.lang.Appendable stderrsb)
          Runs the process whose data is in the ProcessBuilder and captures the result.
static int runProcess(java.lang.ProcessBuilder pb, java.io.Writer out)
          Runs the process whose data is in the ProcessBuilder and captures the result with stdout and stderr merged into a writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

dumpStreams

public static int dumpStreams(java.lang.Process pr,
                              java.lang.Appendable iosb)
                       throws java.lang.Exception
Waits for completion of the command and collect data into the streams.

Throws:
java.lang.Exception

runProcess

public static int runProcess(java.lang.ProcessBuilder pb,
                             java.lang.Appendable sb)
                      throws java.lang.Exception
Runs the process whose data is in the ProcessBuilder and captures the result with stdout and stderr merged.

Parameters:
pb -
sb -
Returns:
Throws:
java.lang.Exception

runProcess

public static int runProcess(java.lang.ProcessBuilder pb,
                             java.io.OutputStream stdout,
                             java.lang.Appendable stderrsb)
                      throws java.lang.Exception
Runs the process whose data is in the ProcessBuilder and captures the result.

Parameters:
pb -
sb -
Returns:
Throws:
java.lang.Exception

runProcess

public static int runProcess(java.lang.ProcessBuilder pb,
                             java.lang.Appendable outsb,
                             java.lang.Appendable errsb)
                      throws java.lang.Exception
Runs the process whose data is in the ProcessBuilder and captures the result with stdout and stderr merged.

Parameters:
pb -
sb -
Returns:
Throws:
java.lang.Exception

runProcess

public static int runProcess(java.lang.ProcessBuilder pb,
                             java.io.Writer out)
                      throws java.lang.Exception
Runs the process whose data is in the ProcessBuilder and captures the result with stdout and stderr merged into a writer.

Parameters:
pb -
sb -
Returns:
Throws:
java.lang.Exception