Package uk.ac.starlink.topcat
Class Executor
- java.lang.Object
-
- uk.ac.starlink.topcat.Executor
-
public abstract class Executor extends java.lang.ObjectDefines an object which can execute a system Process. This is basically a convenience wrapper forProcesswhich 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
Constructors Constructor Description Executor()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static ExecutorcreateExecutor(java.lang.String line)Returns an executor which executes a single command line.static ExecutorcreateExecutor(java.lang.String[] argv)Returns an executor which executes a command made of words.intexecuteSynchronously(boolean isCapture)CallsgetProcess()and attempts to execute it synchronously.java.lang.StringgetErr()Returns the standard error which resulted from running the process, if execution was done in capturing mode.abstract java.lang.StringgetLine()Returns a representation of the command line executed.java.lang.StringgetOut()Returns the standard output which resulted from running the process, if execution was done in capturing mode.abstract java.lang.ProcessgetProcess()Returns a system process to be executed.java.lang.StringtoString()
-
-
-
Method Detail
-
getProcess
public abstract java.lang.Process getProcess() throws java.io.IOExceptionReturns a system process to be executed.- Returns:
- new process
- Throws:
java.io.IOException
-
getLine
public abstract java.lang.String getLine()
Returns a representation of the command line executed.- Returns:
- command line
-
getOut
public java.lang.String getOut()
Returns the standard output which resulted from running the process, if execution was done in capturing mode.- Returns:
- stdout content
-
getErr
public java.lang.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 java.io.IOException, java.lang.InterruptedExceptionCallsgetProcess()and attempts to execute it synchronously. Can be run only once on this object.If
isCaptureis set true, thegetOut()andgetErr()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:
java.io.IOExceptionjava.lang.InterruptedException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
createExecutor
public static Executor createExecutor(java.lang.String line)
Returns an executor which executes a single command line.- Parameters:
line- shell command line- Returns:
- executor
-
createExecutor
public static Executor createExecutor(java.lang.String[] argv)
Returns an executor which executes a command made of words.- Parameters:
argv- argument vector- Returns:
- executor
-
-