org.jostraca.util
Class CommandRunner

java.lang.Object
  extended byorg.jostraca.util.CommandRunner

public class CommandRunner
extends java.lang.Object

Utility class for running a subprocess synchronously from Java and retrieving the contents of System.out and/or system.err.


Nested Class Summary
static class CommandRunner.CharPump
          Inner class, copies from Reader to Writer.
 
Method Summary
static java.lang.String exec(java.lang.String[] pCmd)
          Runs a process using Runtime.exec().
static int exec(java.lang.String[] pCmd, java.io.Writer pOut, java.io.Writer pErr)
          Runs a process using Runtime.exec().
static int exec(java.lang.String pCmd, java.io.Writer pOut, java.io.Writer pErr)
          Runs a process using Runtime.exec().
static void main(java.lang.String[] pArgs)
          Main routine, for testing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

exec

public static java.lang.String exec(java.lang.String[] pCmd)
Runs a process using Runtime.exec(). Collects all output on System.out into a String and returns it, waiting for all output to System.out and System.err, and for completion of the child process. If the exit status is nonzero or there is any output to System.err, this throws a org.jostraca.util.CommandRunner.Exception containing the exit status and error output.


exec

public static int exec(java.lang.String[] pCmd,
                       java.io.Writer pOut,
                       java.io.Writer pErr)
Runs a process using Runtime.exec(). The command to run is passed as a String array. Collects all output on System.out and System.err, passing it to the two Writer parameters. Waits for all output and process completion, writing to the two Writers via the system default character encoding, then returns the process exit status.

Note that if one of the Writers blocks, this may block the child process.


exec

public static int exec(java.lang.String pCmd,
                       java.io.Writer pOut,
                       java.io.Writer pErr)
Runs a process using Runtime.exec(). The command to run is passed as a String. Collects all output on System.out and System.err, passing it to the two Writer parameters. Waits for all output and process completion, writing to the two Writers via the system default character encoding, then returns the process exit status.

Note that if one of the Writers blocks, this may block the child process.


main

public static void main(java.lang.String[] pArgs)
Main routine, for testing. The name of the executable to run and its arguments are the command line arguments.



Copyright © 2000-2002 Richard Rodger