org.ceryle.util
Class ExternalProcess

java.lang.Object
  extended by org.ceryle.util.ExternalProcess

public class ExternalProcess
extends Object

A utility class allowing UNIX process I/O. Because most of these methods are system dependent, applications should first confirm that the OS supports ksh scripting.

The commandLine(String) method uses a simple Runtime request, not the ksh approach.

Since:
JDK1.3
Version:
$Id: ExternalProcess.java,v 3.5 2007-06-15 12:09:55 altheim Exp $
Author:
Murray Altheim

Field Summary
static int SPAWN
          Variable used by getProcessOutput to designating that the process should be spawned, but not to wait for output.
static int STDBOTH
          Variable used by getProcessOutput to designate process output from a concatenation of UNIX stdout and stderr.
static int STDERR
          Variable used by getProcessOutput to designate process output from UNIX stderr.
static int STDOUT
          Variable used by getProcessOutput to designate process output from UNIX stdout.
 
Constructor Summary
ExternalProcess()
          Constructor with an MessageHandler mh.
 
Method Summary
 void commandLine(String s)
          Runs an application on the String s as if it had been typed on the command line.
 void destroy()
          Runs an application on the String s as if it had been typed on the command line.
 StringBuffer getStderr()
          Returns the result of the last commandLine() request's stderr as a StringBuffer, null if unavailable or empty.
 StringBuffer getStdout()
          Returns the result of the last commandLine() request's stdout as a StringBuffer, null if unavailable or empty.
protected  void interpret(String cmd)
          Run a process on the host system from within a shell script, returning the results to the defined output streams.
 void printResult(Iterator it)
          Writes to the MessageHandler the contents of the Iterator it.
 Iterator process(String cmd, int mode)
          Runs the program 'cmd' as a UNIX process, then returns the stderr and/or stdout as a Vector, depending on mode, which can be STDBOTH (writes to both streams), STDERR (writes to stderr), or STDOUT (writes to stdout).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STDOUT

public static int STDOUT
Variable used by getProcessOutput to designate process output from UNIX stdout.


STDERR

public static int STDERR
Variable used by getProcessOutput to designate process output from UNIX stderr.


STDBOTH

public static int STDBOTH
Variable used by getProcessOutput to designate process output from a concatenation of UNIX stdout and stderr.


SPAWN

public static int SPAWN
Variable used by getProcessOutput to designating that the process should be spawned, but not to wait for output.

Constructor Detail

ExternalProcess

public ExternalProcess()
Constructor with an MessageHandler mh.

Method Detail

process

public Iterator process(String cmd,
                        int mode)
Runs the program 'cmd' as a UNIX process, then returns the stderr and/or stdout as a Vector, depending on mode, which can be STDBOTH (writes to both streams), STDERR (writes to stderr), or STDOUT (writes to stdout).

Does not add blank lines to Vector.


destroy

public void destroy()
Runs an application on the String s as if it had been typed on the command line.


commandLine

public void commandLine(String s)
Runs an application on the String s as if it had been typed on the command line. The stdout and stderr result of this can be obtained from getStdout() and getStderr().


getStdout

public StringBuffer getStdout()
Returns the result of the last commandLine() request's stdout as a StringBuffer, null if unavailable or empty.


getStderr

public StringBuffer getStderr()
Returns the result of the last commandLine() request's stderr as a StringBuffer, null if unavailable or empty.


interpret

protected void interpret(String cmd)
                  throws IOException
Run a process on the host system from within a shell script, returning the results to the defined output streams.

Throws:
IOException

printResult

public void printResult(Iterator it)
Writes to the MessageHandler the contents of the Iterator it.



The Ceryle Project. Copyright ©2001-2007 Murray Altheim, All Rights Reserved. See LICENSE included with distribution.