com.cometway.util
Class ExecuteCommand

java.lang.Object
  extended by com.cometway.util.KMethod
      extended by com.cometway.util.ExecuteCommand
All Implemented Interfaces:
java.lang.Runnable

public class ExecuteCommand
extends KMethod
implements java.lang.Runnable

This method extends com.cometway.util.KMethod and implements the Runnable interface, which allows this KMethod to be executed by a PooledThread from a ThreadPool or another Thread. This class provides a simple way of executing System commands via the Runtime.exec() and Process classes/methods.


Field Summary
 boolean changeErrCRtoLF
          Set this to true if Carriage Returns are to be change to Line Feeds in the process' error output.
 boolean changeErrLFtoCR
          Set this to true if Line Feeds are to be change to Carriage Returns in the process' error output.
 boolean changeOutCRtoLF
          Set this to true if Carriage Returns are to be change to Line Feeds in the process' output.
 boolean changeOutLFtoCR
          Set this to true if Line Feeds are to be change to Carriage Returns in the process' output.
 java.lang.String commandInput
          This is the Input sent to the Process OuputStream after execution.
 java.lang.String[] environment
          Set this to the environment variables
 java.lang.Thread execThread
          This is set to the Thread that is executing this KMethod upon execution.
 int finishedWaitTime
          Set this to the number of milliseconds to wait after the process is finished.
 java.lang.StringBuffer processErr
          Set this to the StringBuffer used to store the process' error output.
 ThreadPool processErrThreads
          Set this to the ThreadPool which is used to read the process' error output.
 java.lang.StringBuffer processOut
          Set this to the StringBuffer used to store the process' output.
 ThreadPool processOutThreads
          Set this to the ThreadPool which is used to read the process' output.
 int returnValue
          Return value of the command
 boolean waitForProcess
          Set this to False if the process will not be waited for.
 boolean waitForProcessReaders
          Set this to True if the run() method is to block until the readers read until an End Of Transmission character.
 java.io.File workingDirectory
          Set this to the working directory when the command is executed
 
Fields inherited from class com.cometway.util.KMethod
args, debugName, method, obj, print_errors, run, verbose
 
Constructor Summary
ExecuteCommand(java.lang.String executeString)
           
ExecuteCommand(java.lang.String executeString, java.lang.String commandInput)
           
 
Method Summary
 void execute()
          Calling this will execute this KMethod, which executes what the KMethod wraps.
 boolean isRunning()
           
static void main(java.lang.String[] args)
           
 void run()
           
 void stopProcess()
          This method should be called before the PooledThread is released from the ThreadPool.
 
Methods inherited from class com.cometway.util.KMethod
error, error, print
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

commandInput

public java.lang.String commandInput
This is the Input sent to the Process OuputStream after execution.


execThread

public java.lang.Thread execThread
This is set to the Thread that is executing this KMethod upon execution.


processOutThreads

public ThreadPool processOutThreads
Set this to the ThreadPool which is used to read the process' output.


processErrThreads

public ThreadPool processErrThreads
Set this to the ThreadPool which is used to read the process' error output.


processOut

public java.lang.StringBuffer processOut
Set this to the StringBuffer used to store the process' output. If this is not set, no output is read.


processErr

public java.lang.StringBuffer processErr
Set this to the StringBuffer used to store the process' error output. If this is not set, no error output is read.


waitForProcess

public boolean waitForProcess
Set this to False if the process will not be waited for. This means that run() will not wait for the Process to finish.


waitForProcessReaders

public boolean waitForProcessReaders
Set this to True if the run() method is to block until the readers read until an End Of Transmission character. If this option is set with the 'finishedWaitTime' option, the method will only block for 'finishedWaitTime' milliseconds.


finishedWaitTime

public int finishedWaitTime
Set this to the number of milliseconds to wait after the process is finished. This guarantees that the output and error readers will read all the available input on some JVMs. If the 'waitForProcessReaders' flag is set to true, this field denotes how long to wait for the process' output.


changeOutLFtoCR

public boolean changeOutLFtoCR
Set this to true if Line Feeds are to be change to Carriage Returns in the process' output.


changeOutCRtoLF

public boolean changeOutCRtoLF
Set this to true if Carriage Returns are to be change to Line Feeds in the process' output.


changeErrLFtoCR

public boolean changeErrLFtoCR
Set this to true if Line Feeds are to be change to Carriage Returns in the process' error output.


changeErrCRtoLF

public boolean changeErrCRtoLF
Set this to true if Carriage Returns are to be change to Line Feeds in the process' error output.


returnValue

public int returnValue
Return value of the command


workingDirectory

public java.io.File workingDirectory
Set this to the working directory when the command is executed


environment

public java.lang.String[] environment
Set this to the environment variables

Constructor Detail

ExecuteCommand

public ExecuteCommand(java.lang.String executeString)

ExecuteCommand

public ExecuteCommand(java.lang.String executeString,
                      java.lang.String commandInput)
Method Detail

execute

public void execute()
Description copied from class: KMethod
Calling this will execute this KMethod, which executes what the KMethod wraps.

Overrides:
execute in class KMethod

run

public void run()
Specified by:
run in interface java.lang.Runnable

isRunning

public boolean isRunning()

stopProcess

public void stopProcess()
This method should be called before the PooledThread is released from the ThreadPool.


main

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