net.groboclown.util.thread.v1
Class BackgroundProcess

java.lang.Object
  |
  +--net.groboclown.util.thread.v1.BackgroundProcess

public class BackgroundProcess
extends Object

Creates and executes the given process. Ensures that all the output is properly read without overflowing or dead-locking the process. Outside of the streaming, this class has an identical API to that of Process.

Creation of a background process begins at the creation of this object.

Changes for 0.9.1d

Since:
0.9.1b
Version:
0.9.1d
Author:
Matt Albrecht

Field Summary
private  PipedInputStream errReader
           
private  IOThreadRunner errThread
           
private  PipedOutputStream errWriter
           
private  PipedInputStream outReader
           
private  IOThreadRunner outThread
           
private  PipedOutputStream outWriter
           
private  Process proc
           
private  OutputStream stdIn
           
 
Constructor Summary
BackgroundProcess(Process p)
          Initializes the background process with an existing process.
BackgroundProcess(String command)
           
BackgroundProcess(String[] cmdarray)
           
BackgroundProcess(String[] cmdarray, String[] envp)
           
BackgroundProcess(String[] cmdarray, String[] envp, File dir)
           
BackgroundProcess(String command, String[] envp)
           
BackgroundProcess(String command, String[] envp, File dir)
           
 
Method Summary
 void destroy()
           
 int exitValue()
           
 InputStream getStdErr()
          Get the InputStream that retrieves the data from the StdErr of the process.
 OutputStream getStdIn()
          Get the OutputStream that is sent to the StdIn of the process.
 InputStream getStdOut()
          Get the InputStream that retrieves the data from the StdOut of the process.
protected  void setupProcess(Process p)
          Initalize the process for internal use.
 int waitFor()
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

proc

private Process proc

stdIn

private OutputStream stdIn

outReader

private PipedInputStream outReader

outWriter

private PipedOutputStream outWriter

errReader

private PipedInputStream errReader

errWriter

private PipedOutputStream errWriter

outThread

private IOThreadRunner outThread

errThread

private IOThreadRunner errThread
Constructor Detail

BackgroundProcess

public BackgroundProcess(String command)
                  throws IOException
See Also:
java.lang.Runtime#exec( String )

BackgroundProcess

public BackgroundProcess(String[] cmdarray)
                  throws IOException
See Also:
java.lang.Runtime#exec( String[] )

BackgroundProcess

public BackgroundProcess(String[] cmdarray,
                         String[] envp,
                         File dir)
                  throws IOException
See Also:
java.lang.Runtime#exec( String[], String[], File )

BackgroundProcess

public BackgroundProcess(String command,
                         String[] envp,
                         File dir)
                  throws IOException
See Also:
java.lang.Runtime#exec( String, String[], File )

BackgroundProcess

public BackgroundProcess(String[] cmdarray,
                         String[] envp)
                  throws IOException
See Also:
java.lang.Runtime#exec( String[], String[] )

BackgroundProcess

public BackgroundProcess(String command,
                         String[] envp)
                  throws IOException
See Also:
java.lang.Runtime#exec( String, String[] )

BackgroundProcess

public BackgroundProcess(Process p)
                  throws IOException
Initializes the background process with an existing process.
Method Detail

getStdIn

public OutputStream getStdIn()
Get the OutputStream that is sent to the StdIn of the process.

getStdOut

public InputStream getStdOut()
Get the InputStream that retrieves the data from the StdOut of the process.

getStdErr

public InputStream getStdErr()
Get the InputStream that retrieves the data from the StdErr of the process.

destroy

public void destroy()
See Also:
Process.destroy()

exitValue

public int exitValue()
See Also:
Process.exitValue()

waitFor

public int waitFor()
            throws InterruptedException
See Also:
Process.waitFor()

setupProcess

protected void setupProcess(Process p)
                     throws IOException
Initalize the process for internal use.


Written under the LGPL