consciouscode.util
Class ProcessRunner

java.lang.Object
  extended by consciouscode.util.ProcessRunner
Direct Known Subclasses:
VmForker

public class ProcessRunner
extends Object


Nested Class Summary
 class ProcessRunner.StreamCopier
           
 
Field Summary
static String DEFAULT_PROCESS_TAG
           
static int INTERRUPTED
           
 
Constructor Summary
ProcessRunner(String[] command)
           
ProcessRunner(String[] command, String processTag)
           
 
Method Summary
 void destroy()
           
 void fork()
          Fork a new process.
 String[] getCommand()
          Gets the command line that is used for the child process.
 boolean getDestroyOnShutdown()
          Indicate whether the forked Process will be destroyed when this JVM is shut down.
 int getProcessExitValue()
           
 OutputStream getProcessStdIn()
          Gets a stream connected to the standard input stream of the running process.
 String getProcessTag()
           
 boolean isProcessRunning()
           
 void setDestroyOnShutdown(boolean destroy)
           
 void setProcessTag(String tag)
           
 void setStdErr(Writer writer)
           
 void setStdOut(Writer writer)
           
 void waitForExit()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INTERRUPTED

public static final int INTERRUPTED
See Also:
Constant Field Values

DEFAULT_PROCESS_TAG

public static final String DEFAULT_PROCESS_TAG
See Also:
Constant Field Values
Constructor Detail

ProcessRunner

public ProcessRunner(String[] command)

ProcessRunner

public ProcessRunner(String[] command,
                     String processTag)
Method Detail

getCommand

public String[] getCommand()
Gets the command line that is used for the child process. Subclasses can override this method to compute the command line dynamically.


getProcessTag

public String getProcessTag()

setProcessTag

public void setProcessTag(String tag)

getDestroyOnShutdown

public boolean getDestroyOnShutdown()
Indicate whether the forked Process will be destroyed when this JVM is shut down. The value can be changed even after the process has been forked.

By default, this property is true.


setDestroyOnShutdown

public void setDestroyOnShutdown(boolean destroy)

setStdOut

public void setStdOut(Writer writer)

setStdErr

public void setStdErr(Writer writer)

fork

public void fork()
          throws IOException
Fork a new process.

PRECONDITION: ! isRunning()

Throws:
IOException - if an I/O error occurs while forking the process.

isProcessRunning

public boolean isProcessRunning()

getProcessStdIn

public OutputStream getProcessStdIn()
Gets a stream connected to the standard input stream of the running process.

Returns:
an output steam that can be used to send input to the child process, or null if the process is not running.

getProcessExitValue

public int getProcessExitValue()

waitForExit

public void waitForExit()

destroy

public void destroy()


Copyright © 2001–2012 Todd V. Jonker. All Rights Reserved.