net.sourceforge.groboutils.util.thread.v1
Class BackgroundProcess

java.lang.Object
  extended bynet.sourceforge.groboutils.util.thread.v1.BackgroundProcess

public class BackgroundProcess
extends java.lang.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:
June 4, 2000 (0.9.1d Alpha)
Version:
$Date: 2003/02/10 22:52:48 $
Author:
Matt Albrecht groboclown@users.sourceforge.net

Constructor Summary
BackgroundProcess(java.lang.Process p)
          Initializes the background process with an existing process.
BackgroundProcess(java.lang.String command)
           
BackgroundProcess(java.lang.String[] cmdarray)
           
BackgroundProcess(java.lang.String[] cmdarray, java.lang.String[] envp)
           
BackgroundProcess(java.lang.String[] cmdarray, java.lang.String[] envp, java.io.File dir)
           
BackgroundProcess(java.lang.String command, java.lang.String[] envp)
           
BackgroundProcess(java.lang.String command, java.lang.String[] envp, java.io.File dir)
           
 
Method Summary
 void destroy()
           
protected static java.lang.Process exec(java.lang.String[] cmd, java.lang.String[] env, java.io.File dir)
           
protected  java.lang.Process exec(java.lang.String cmd, java.lang.String[] env, java.io.File dir)
          Invoke the correct Exec method for the given parameters.
 int exitValue()
           
 java.io.InputStream getStdErr()
          Get the InputStream that retrieves the data from the StdErr of the process.
 java.io.OutputStream getStdIn()
          Get the OutputStream that is sent to the StdIn of the process.
 java.io.InputStream getStdOut()
          Get the InputStream that retrieves the data from the StdOut of the process.
protected static java.lang.Process reflectExec(java.lang.Object cmd, java.lang.String[] env, java.io.File dir)
          Attempts to invoke the JDK 1.3 exec method with the given dir.
protected static java.lang.String[] setPWD(java.lang.String[] env, java.io.File dir)
          Don't change env!
protected  void setupProcess(java.lang.Process p)
          Initalize the process for internal use.
 int waitFor()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BackgroundProcess

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

BackgroundProcess

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

BackgroundProcess

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

BackgroundProcess

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

BackgroundProcess

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

BackgroundProcess

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

BackgroundProcess

public BackgroundProcess(java.lang.Process p)
                  throws java.io.IOException
Initializes the background process with an existing process.

Method Detail

getStdIn

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


getStdOut

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


getStdErr

public java.io.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 java.lang.InterruptedException
Throws:
java.lang.InterruptedException
See Also:
Process.waitFor()

setupProcess

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

Throws:
java.io.IOException

exec

protected java.lang.Process exec(java.lang.String cmd,
                                 java.lang.String[] env,
                                 java.io.File dir)
                          throws java.io.IOException
Invoke the correct Exec method for the given parameters.

Throws:
java.io.IOException

exec

protected static java.lang.Process exec(java.lang.String[] cmd,
                                        java.lang.String[] env,
                                        java.io.File dir)
                                 throws java.io.IOException
Throws:
java.io.IOException

reflectExec

protected static java.lang.Process reflectExec(java.lang.Object cmd,
                                               java.lang.String[] env,
                                               java.io.File dir)
                                        throws java.io.IOException
Attempts to invoke the JDK 1.3 exec method with the given dir. cmd is either a String or String[] type.

Returns:
the generated Process. If the process is null, then another technique must be used to execute the command.
Throws:
java.io.IOException

setPWD

protected static java.lang.String[] setPWD(java.lang.String[] env,
                                           java.io.File dir)
Don't change env!



Copyright © 2001-2003 by The GroboUtils Project