simtools.util
Class SysExec

java.lang.Object
  extended by simtools.util.SysExec

public class SysExec
extends java.lang.Object

This class defines a way to execute system commands

Version:
1.0, 12/11/97
Author:
Jean-Louis PATANE

Nested Class Summary
static interface SysExec.ErrOutWriter
          Inner interface for output & error streams.
 
Field Summary
 java.lang.String errorMessage
           
 simtools.util.SysExec.ErrPrintThread errPrintThread
          This thread manages with the stderr of the process.
static int EXEC_ERROR
          Constant for process execution error.
 int exitValue
          The exit value of the process (0 == ok)
 boolean finished
          This flag is used by children threads to know if the process is terminated.
static int KILL_ERROR
          Constant for process execution error.
static int MISS_ERROR
          Constant for process execution error.
 simtools.util.SysExec.OutPrintThread outPrintThread
          This thread manages with the stdout of the process.
static int READ_ERROR
          Constant for process execution error.
static int SYNC_ERROR
          Constant for process execution error.
static int WAIT_ERROR
          Constant for process execution error.
 simtools.util.SysExec.WaitThread waitThread
          This thread waits for the end of the process.
 
Constructor Summary
SysExec()
          Initialization of the instance with an empty vector of process execution commands.
SysExec(boolean dumpToLogger)
           
SysExec(SysExec.ErrOutWriter theWriter)
           
 
Method Summary
 void add(java.lang.String cmd)
          Append a command at the end of the command line currently built.
 boolean addEnvVariable(java.lang.String variableName, java.lang.String variableValue)
          add an environment variable
 void errPrintln(java.lang.String line)
          This method can be overwritten in a derived class to catch each text line sent by the process in its stderr.
 void killAll()
          Stops the currently working process.
static void main(java.lang.String[] args)
           
 void outPrintln(java.lang.String line)
          This method can be overwritten in a derived class to catch each text line sent by the process in its stdout.
 void print()
           
 void reset()
          Remove all commands in the command line currently built.
 int run()
          Create an external child process to execute the command line currently built, and wait for this process terminates.
 boolean setWorkingDirectory(java.lang.String workingDirectoryPath)
          set working directory for SysExec
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MISS_ERROR

public static final int MISS_ERROR
Constant for process execution error.

See Also:
Constant Field Values

WAIT_ERROR

public static final int WAIT_ERROR
Constant for process execution error.

See Also:
Constant Field Values

EXEC_ERROR

public static final int EXEC_ERROR
Constant for process execution error.

See Also:
Constant Field Values

READ_ERROR

public static final int READ_ERROR
Constant for process execution error.

See Also:
Constant Field Values

SYNC_ERROR

public static final int SYNC_ERROR
Constant for process execution error.

See Also:
Constant Field Values

KILL_ERROR

public static final int KILL_ERROR
Constant for process execution error.

See Also:
Constant Field Values

finished

public boolean finished
This flag is used by children threads to know if the process is terminated.


exitValue

public int exitValue
The exit value of the process (0 == ok)


errorMessage

public java.lang.String errorMessage

outPrintThread

public simtools.util.SysExec.OutPrintThread outPrintThread
This thread manages with the stdout of the process.


errPrintThread

public simtools.util.SysExec.ErrPrintThread errPrintThread
This thread manages with the stderr of the process.


waitThread

public simtools.util.SysExec.WaitThread waitThread
This thread waits for the end of the process.

Constructor Detail

SysExec

public SysExec()
Initialization of the instance with an empty vector of process execution commands.


SysExec

public SysExec(SysExec.ErrOutWriter theWriter)
Parameters:
theWriter: - an ErrOutWriter object (for output & error streams)

SysExec

public SysExec(boolean dumpToLogger)
Parameters:
dumpToLogger: - an logger object (for output & error streams)
Method Detail

reset

public void reset()
Remove all commands in the command line currently built.


add

public void add(java.lang.String cmd)
Append a command at the end of the command line currently built.

Parameters:
command - to append at the end of the command line
See Also:
UNIX_PreProcH, MSDOS_PreProc

killAll

public void killAll()
Stops the currently working process.


setWorkingDirectory

public boolean setWorkingDirectory(java.lang.String workingDirectoryPath)
set working directory for SysExec

Parameters:
workingDirectoryPath - : the path
Returns:
: true if the working has been correctly set

addEnvVariable

public boolean addEnvVariable(java.lang.String variableName,
                              java.lang.String variableValue)
add an environment variable

Parameters:
variableName - : the name of the variable
variableValue - : th value of the variable
Returns:
: true if the variable has been correctly added and, else false

run

public int run()
Create an external child process to execute the command line currently built, and wait for this process terminates.

Returns:
the exit value of the process (0 == ok)
See Also:
UNIX_PreProcH, MSDOS_PreProc

outPrintln

public void outPrintln(java.lang.String line)
This method can be overwritten in a derived class to catch each text line sent by the process in its stdout.

Parameters:
line - A text line sent by the process in its stdout.

errPrintln

public void errPrintln(java.lang.String line)
This method can be overwritten in a derived class to catch each text line sent by the process in its stderr.

Parameters:
line - A text line sent by the process in its stderr.

print

public void print()

main

public static void main(java.lang.String[] args)