Expresso 5-6

com.jcorporate.expresso.core.misc
Class OSProcess

java.lang.Object
  extended byjava.lang.Thread
      extended bycom.jcorporate.expresso.core.misc.OSProcess
All Implemented Interfaces:
Runnable

public class OSProcess
extends Thread

This is a class that wraps another process in the machine. It is not like the ANT wrappers that can launch another java program with full environment of the parent, but you can launch other java programs through command line usage.

Typical usage:

 OSProcess process = new OSProcess("/usr/bin/perl /home/mydir/scripts/updatecounts.pl");
 process.runProcess();
 

//Now print out the results to std out. Vector result = process.getStdout(); for (Iterator i = result.iterator(); i.hasNext(); ) { System.out.println((String)i.next()); }

Author:
Michael Nash

Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
OSProcess(String commandLine)
          Constructor
 
Method Summary
 DBException getException()
          ??
 int getExitValue()
          Retrieve the operating system exit value.
 Vector getStderr()
          Retrieve a vector of all lines printed to std error
 Vector getStdout()
          Retrieve a vector of all lines printed to std out
static void main(String[] args)
          Test-harness method to allow OSProcess to be run & tested from the command line
 void run()
          Run the process - do not call this method directly!
 void runProcess()
          Run the process on the server, timing out when required
 void setTimeOut(long newSleepInterval, int newMaxSleeps)
          Set a timeout for the command
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OSProcess

public OSProcess(String commandLine)
Constructor

Parameters:
commandLine - The command line to execute on the server
Method Detail

getException

public DBException getException()
??

Returns:

getExitValue

public int getExitValue()
                 throws DBException
Retrieve the operating system exit value.

Returns:
Throws:
DBException

getStderr

public Vector getStderr()
Retrieve a vector of all lines printed to std error

Returns:
java.util.Vector of Strings

getStdout

public Vector getStdout()
Retrieve a vector of all lines printed to std out

Returns:
java.util.Vector

main

public static void main(String[] args)
Test-harness method to allow OSProcess to be run & tested from the command line

Parameters:
args -

run

public void run()
Run the process - do not call this method directly! Call runProcess above and it will handle the timeouts correctly


runProcess

public void runProcess()
                throws DBException
Run the process on the server, timing out when required

Throws:
DBException - If the process times out

setTimeOut

public void setTimeOut(long newSleepInterval,
                       int newMaxSleeps)
Set a timeout for the command

Parameters:
newSleepInterval - Number of seconds to sleep between checks
newMaxSleeps - Number of times to check before timing out

Expresso 5-6

Please see www.jcorporate.com for information about new Expresso releases.