org.eclipse.core.tests.session
Class ProcessController

java.lang.Object
  extended by org.eclipse.core.tests.session.ProcessController

public class ProcessController
extends java.lang.Object

Executes an external process synchronously, allowing the client to define a maximum amount of time for the process to complete.


Nested Class Summary
 class ProcessController.TimeOutException
          Thrown when a process being executed exceeds the maximum amount of time allowed for it to complete.
 
Constructor Summary
ProcessController(long timeout, java.lang.String[] params)
          Constructs an instance of ProcessController.
 
Method Summary
 int execute()
          Causes the process to start executing.
 void forwardErrorOutput(java.io.OutputStream err)
          Forwards the process standard error output to the given output stream.
 void forwardInput(java.io.InputStream in)
          Forwards the given input stream to the process standard input.
 void forwardOutput(java.io.OutputStream out)
          Forwards the process standard output to the given output stream.
 java.lang.Process getProcess()
          Returns the controled process.
 void kill()
          Kills the process.
 boolean wasKilled()
          Returns whether the process was killed due to a time out.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProcessController

public ProcessController(long timeout,
                         java.lang.String[] params)
Constructs an instance of ProcessController. This does not creates an OS process. run() does that.

Parameters:
timeout - the maximum time the process should take to run
params - the parameters to be passed to the controlled process
Method Detail

execute

public int execute()
            throws java.lang.InterruptedException,
                   java.io.IOException,
                   ProcessController.TimeOutException
Causes the process to start executing. This call will block until the process has completed. If timeout is specified, the process will be interrupted if it takes more than the specified amount of time to complete, causing a TimedOutException to be thrown. Specifying zero as timeout means the process is not time constrained.

Returns:
the process exit value
Throws:
java.lang.InterruptedException
java.io.IOException
ProcessController.TimeOutException - if the process did not complete in time

forwardErrorOutput

public void forwardErrorOutput(java.io.OutputStream err)
Forwards the process standard error output to the given output stream. Must be called before execution has started.

Parameters:
err - an output stream where to forward the process standard error output to

forwardOutput

public void forwardOutput(java.io.OutputStream out)
Forwards the process standard output to the given output stream. Must be called before execution has started.

Parameters:
out - an output stream where to forward the process standard output to

getProcess

public java.lang.Process getProcess()
Returns the controled process. Will return null before execute is called.

Returns:
the underlying process

kill

public void kill()
Kills the process. Does nothing if it has been finished already.


wasKilled

public boolean wasKilled()
Returns whether the process was killed due to a time out.

Returns:
true if the process was killed, false if the completed normally

forwardInput

public void forwardInput(java.io.InputStream in)
Forwards the given input stream to the process standard input. Must be called before execution has started.

Parameters:
in - an input stream where the process standard input will be forwarded to