uk.ac.starlink.topcat
Class Executor

java.lang.Object
  extended by uk.ac.starlink.topcat.Executor

public abstract class Executor
extends Object

Defines an object which can execute a system Process. This is basically a convenience wrapper for Process which takes care of the stream output and so on. It's not completely general purpose, it's designed for running little shell commands - if you try to run something which spews out a huge amount of output you could have trouble.

Since:
9 Jun 2005
Author:
Mark Taylor (Starlink)

Constructor Summary
Executor()
           
 
Method Summary
static Executor createExecutor(String line)
          Returns an executor which executes a single command line.
static Executor createExecutor(String[] argv)
          Returns an executor which executes a command made of words.
 int executeSynchronously(boolean isCapture)
          Calls getProcess() and attempts to execute it synchronously.
 String getErr()
          Returns the standard error which resulted from running the process, if execution was done in capturing mode.
abstract  String getLine()
          Returns a representation of the command line executed.
 String getOut()
          Returns the standard output which resulted from running the process, if execution was done in capturing mode.
abstract  Process getProcess()
          Returns a system process to be executed.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Executor

public Executor()
Method Detail

getProcess

public abstract Process getProcess()
                            throws IOException
Returns a system process to be executed.

Returns:
new process
Throws:
IOException

getLine

public abstract String getLine()
Returns a representation of the command line executed.

Returns:
command line

getOut

public String getOut()
Returns the standard output which resulted from running the process, if execution was done in capturing mode.

Returns:
stdout content

getErr

public String getErr()
Returns the standard error which resulted from running the process, if execution was done in capturing mode.

Returns:
stderr content

executeSynchronously

public int executeSynchronously(boolean isCapture)
                         throws IOException,
                                InterruptedException
Calls getProcess() and attempts to execute it synchronously. Can be run only once on this object.

If isCapture is set true, the getOut() and getErr() methods can be used after this call to get the results from stdout and stderr. Otherwise, the process output streams go to the JVM's stdout/stderr.

Parameters:
isCapture - true to capture output and return it as the outcome message, false to let it go to stdout
Returns:
exit status (0 is OK)
Throws:
IOException
InterruptedException

toString

public String toString()
Overrides:
toString in class Object

createExecutor

public static Executor createExecutor(String line)
Returns an executor which executes a single command line.

Parameters:
line - shell command line
Returns:
executor

createExecutor

public static Executor createExecutor(String[] argv)
Returns an executor which executes a command made of words.

Parameters:
argv - argument vector
Returns:
executor


Copyright © 2003-2018 CCLRC: Council for the Central Laboratory of the Research Councils. All Rights Reserved.