net.sourceforge.cruisecontrol.util
Class CommandExecutor

java.lang.Object
  extended bynet.sourceforge.cruisecontrol.util.CommandExecutor

public class CommandExecutor
extends java.lang.Object

Class for executing a . It setups an extra thread to consume stderr and blocks until the process and the extra thread has finished.


Constructor Summary
CommandExecutor(Commandline command)
          Creates a new instance of CommandExecutor.
CommandExecutor(Commandline command, org.apache.log4j.Logger log)
          Creates a new instance of CommandExecutor.
 
Method Summary
 int executeAndWait()
          Executes the command and wait for the process to finish.
 void logErrorStreamTo(org.apache.log4j.Logger log)
          Sends the process' error stream (stderr) to a log as warnings.
 void logOutputStreamTo(org.apache.log4j.Logger log)
          Sends the process' output stream (stdout) to a log as info.
 void setOutputConsumer(StreamConsumer outConsumer)
          Sends the process' output stream (stdout) to a StreamConsumer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandExecutor

public CommandExecutor(Commandline command)
Creates a new instance of CommandExecutor.


CommandExecutor

public CommandExecutor(Commandline command,
                       org.apache.log4j.Logger log)
Creates a new instance of CommandExecutor.

Method Detail

logErrorStreamTo

public void logErrorStreamTo(org.apache.log4j.Logger log)
Sends the process' error stream (stderr) to a log as warnings.

Parameters:
log - where to log the error stream.

logOutputStreamTo

public void logOutputStreamTo(org.apache.log4j.Logger log)
Sends the process' output stream (stdout) to a log as info.

Parameters:
log - where to log the output stream.

setOutputConsumer

public void setOutputConsumer(StreamConsumer outConsumer)
Sends the process' output stream (stdout) to a StreamConsumer.

Parameters:
outConsumer - consumes the process's output stream.

executeAndWait

public int executeAndWait()
                   throws java.io.IOException,
                          java.lang.InterruptedException
Executes the command and wait for the process to finish.

Returns:
the process' exit value
Throws:
java.io.IOException
java.lang.InterruptedException