nl.knowledgeplaza.util
Class Exec

java.lang.Object
  extended by java.lang.Thread
      extended by nl.knowledgeplaza.util.Exec
All Implemented Interfaces:
java.lang.Runnable

public class Exec
extends java.lang.Thread

Implements an exec() interface. The primary reason for this class is to insulate the developer from the vagaries of Runtime.exec(), which appears to have a number of problems depending on the environment in which it is run.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Exec(java.lang.String[] argv, java.lang.String[] envp)
          Create an exec object that will throw away all output.
Exec(java.lang.String[] argv, java.lang.String[] envp, java.io.PrintWriter pWriter)
          Create an exec object that will write output to a PrintWriter.
Exec(java.lang.String[] argv, java.lang.String[] envp, java.lang.StringBuffer sBuffer)
          Create an exec object that will write output into StringBuffer.
 
Method Summary
 void debugExec(java.lang.StringBuffer buf)
          Use this to append the parameters into the results.
 void dump()
          Use this to dump the parameters to System.err.
 void exec()
          Run the program.
 int getExitValue()
          Get the exit value of the exec().
 void run()
          Runtime.exec() has a problem in that is the output streams (stdout and stderr) are not read in a timely manner (Bug parade indicates 512 byte buffers), the process will HANG as the stream BLOCKS forever on readLn().
 void setErrPrefix(java.lang.String errPfx)
          Set the string that will prefix all stderr lines.
 void setOutPrefix(java.lang.String outPfx)
          Set the string that will prefix all stdout lines.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, 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

Exec

public Exec(java.lang.String[] argv,
            java.lang.String[] envp)
Create an exec object that will throw away all output.


Exec

public Exec(java.lang.String[] argv,
            java.lang.String[] envp,
            java.lang.StringBuffer sBuffer)
Create an exec object that will write output into StringBuffer.


Exec

public Exec(java.lang.String[] argv,
            java.lang.String[] envp,
            java.io.PrintWriter pWriter)
Create an exec object that will write output to a PrintWriter.

Method Detail

setErrPrefix

public void setErrPrefix(java.lang.String errPfx)
Set the string that will prefix all stderr lines.


setOutPrefix

public void setOutPrefix(java.lang.String outPfx)
Set the string that will prefix all stdout lines.


getExitValue

public int getExitValue()
Get the exit value of the exec(). The value is not valid until exec() completes.


exec

public void exec()
Run the program.


run

public void run()
Runtime.exec() has a problem in that is the output streams (stdout and stderr) are not read in a timely manner (Bug parade indicates 512 byte buffers), the process will HANG as the stream BLOCKS forever on readLn(). To fix this, we must start a thread for each stream to help ensure the data is read in a timely fashion.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

dump

public void dump()
Use this to dump the parameters to System.err.


debugExec

public void debugExec(java.lang.StringBuffer buf)
Use this to append the parameters into the results.



Copyright © 2010. All Rights Reserved.