be.destin.util
Class RunCommand

java.lang.Object
  extended by be.destin.util.RunCommand
All Implemented Interfaces:
java.lang.Runnable

public class RunCommand
extends java.lang.Object
implements java.lang.Runnable

Allows to run synchronously external programs or operating system commands scripts, providing an input (as a string) and receiving output and errors (also as strings). Has been proven rather robust: execution of GraphWiz, batch files with FTP transfer...

Author:
Christophe Dupriez

Constructor Summary
RunCommand(java.lang.String directory, java.lang.String[] commandSegments, java.lang.String[] envp)
          Prepares a command line to be executed.
 
Method Summary
static void closeAble(java.io.Closeable toClose, java.lang.String mess)
           
 java.lang.String getErrors()
          System.err() from executed command.
 int getExitValue()
          Exit code.
 java.lang.String getInput()
           
 java.lang.String getOutput()
          System.out() from executed command.
 long getSequence()
          sequence: rank of the last execution.
 void run()
          Execute the command line and wait for its completion.
 void setExitValue(int exitValue)
          No foreseen use.
 void setInput(java.lang.String input)
          Input for executed command.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RunCommand

public RunCommand(java.lang.String directory,
                  java.lang.String[] commandSegments,
                  java.lang.String[] envp)
Prepares a command line to be executed.

Parameters:
directory - Default directory when executing
commandSegments - Individual segments of the command line to be executed.
envp - Environment variables (Each string in the format KEY=VALUE)
Method Detail

closeAble

public static void closeAble(java.io.Closeable toClose,
                             java.lang.String mess)

run

public void run()
Execute the command line and wait for its completion.

Specified by:
run in interface java.lang.Runnable
See Also:
Runnable.run()

getSequence

public long getSequence()
sequence: rank of the last execution.

Returns:
How many times a command was executed

getErrors

public java.lang.String getErrors()
System.err() from executed command.

Returns:
A String with what the executed command wrote on stderr:

getOutput

public java.lang.String getOutput()
System.out() from executed command.

Returns:
A String with what the executed command wrote on stdout:

getInput

public java.lang.String getInput()
Returns:
the String which has been provided as stdin: for command

setInput

public void setInput(java.lang.String input)
Input for executed command.

Parameters:
input - String provided as the stdin: for the command to be executed

getExitValue

public int getExitValue()
Exit code.

Returns:
executed command exit code (0 = success)

setExitValue

public void setExitValue(int exitValue)
No foreseen use.