net.sourceforge.fluxion.spi.utils
Class ProcessRunner

java.lang.Object
  extended by net.sourceforge.fluxion.spi.utils.ProcessRunner

public class ProcessRunner
extends java.lang.Object

A utility class that simplifies the process of delegating to external processes and waiting for the output. By instantiating a new ProcessRunner and sending it the command you wish to execute in the current runtime environment, calling classes will acquire a string array that contains the lines output by the native process.

Author:
Tony Burdett

Constructor Summary
ProcessRunner()
           
 
Method Summary
 void redirectStderr(boolean redirect)
          Whether or not to redirect the standard error stream of the native process to standard out.
 java.lang.String[] runCommmand(java.lang.String command)
          Execute the string as a native system process.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProcessRunner

public ProcessRunner()
Method Detail

redirectStderr

public void redirectStderr(boolean redirect)
Whether or not to redirect the standard error stream of the native process to standard out. True to redirect.

Parameters:
redirect - true redirects stdout to stderr

runCommmand

public java.lang.String[] runCommmand(java.lang.String command)
                               throws java.io.IOException
Execute the string as a native system process. The string passed should be appropriate for the OS on the system where the program is running, so note that usage of this class may make code system dependent. This method blocks until the process has completed, and then returns any output of the process as a String[].

Parameters:
command - The command to be executed. Should be appropriate for the OS
Returns:
the output of the process
Throws:
java.io.IOException - if the process exited with an error exit code, or there was a problem executing the process


Copyright © 2010. All Rights Reserved.