org.opensubsystems.core.util
Class ProcessExec

java.lang.Object
  extended by org.opensubsystems.core.util.ProcessExec

public final class ProcessExec
extends java.lang.Object

Utility class for correct executing external processes. This class was insipred by article http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

Version:
$Id: ProcessExec.java,v 1.5 2007/01/07 06:14:00 bastafidli Exp $
Author:
Miro Halas
Code reviewer:
Miro Halas
Code reviewed:
Initial revision

Field Summary
static int INTERRUPTED_PROCESS_RETURN_VALUE
          Return value used when waiting for process to finish was interrupted.
static java.lang.Integer INTERRUPTED_PROCESS_RETURN_VALUE_OBJ
          Return value used when waiting for process to finish was interrupted.
 
Method Summary
static java.lang.Object[] execute(java.lang.String[] commandline, java.lang.String[] environment, java.io.File workingDir, boolean bCapture, long lMaxCaptureSize)
          Execute specified command or process and returns immidiately even before the command finished.
static java.lang.Object[] execute(java.lang.String commandline, boolean bCapture)
          Execute specified command or process and returns immidiately even before the command finished.
static java.lang.Object[] executeAndWait(java.lang.String[] commandline, java.lang.String[] environment, java.io.File workingDir, boolean bCapture, long lMaxCaptureSize)
          Execute specified command or process and returns immidiately even before the command finished.
static java.lang.Object[] executeAndWait(java.lang.String commandline, boolean bCapture)
          Execute specified command or process and returns immidiately even before the command finished.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INTERRUPTED_PROCESS_RETURN_VALUE

public static final int INTERRUPTED_PROCESS_RETURN_VALUE
Return value used when waiting for process to finish was interrupted.

See Also:
Constant Field Values

INTERRUPTED_PROCESS_RETURN_VALUE_OBJ

public static final java.lang.Integer INTERRUPTED_PROCESS_RETURN_VALUE_OBJ
Return value used when waiting for process to finish was interrupted.

Method Detail

executeAndWait

public static java.lang.Object[] executeAndWait(java.lang.String commandline,
                                                boolean bCapture)
                                         throws java.io.IOException,
                                                OSSException
Execute specified command or process and returns immidiately even before the command finished.

Parameters:
commandline - - array containing the command to call and its arguments, see Runtime.exec for more description
bCapture - - if true then the output and error will be captured (carefull about memory) and can be read
Returns:
Object[] - index 0 - Integer value of the exit code - index 1 - StreamGobbler for the output stream - index 2 - StreamGobbler for the error stream
Throws:
java.io.IOException - - error in function
OSSException - - error in function

executeAndWait

public static java.lang.Object[] executeAndWait(java.lang.String[] commandline,
                                                java.lang.String[] environment,
                                                java.io.File workingDir,
                                                boolean bCapture,
                                                long lMaxCaptureSize)
                                         throws java.io.IOException
Execute specified command or process and returns immidiately even before the command finished.

Parameters:
commandline - - array containing the command to call and its arguments, see Runtime.exec for more description
environment - - array containing the environment for the process or just null to inherit environment, see Runtime.exec for more description
workingDir - - current working directory for the process or just null to inherit from parent see Runtime.exec for more description
bCapture - - if true then the output and error will be captured (carefull about memory) and can be read
lMaxCaptureSize - - maximal size of EACH output to be held in memory.
Returns:
Object[] - index 0 - Integer value of the exit code - index 1 - StreamGobbler for the output stream - index 2 - StreamGobbler for the error stream
Throws:
java.io.IOException - - error in function

execute

public static java.lang.Object[] execute(java.lang.String commandline,
                                         boolean bCapture)
                                  throws java.io.IOException,
                                         OSSException
Execute specified command or process and returns immidiately even before the command finished.

Parameters:
commandline - - String containing the command to call and its arguments it will be parsed to follow requirements of Runtime.exec
bCapture - - if true then the output and error will be captured (carefull about memory) and can be read
Returns:
Object[] - index 0 - Process object for the executed process - index 1 - StreamGobbler for the output stream - index 2 - StreamGobbler for the error stream
Throws:
java.io.IOException - - error in function
OSSException - - error in function

execute

public static java.lang.Object[] execute(java.lang.String[] commandline,
                                         java.lang.String[] environment,
                                         java.io.File workingDir,
                                         boolean bCapture,
                                         long lMaxCaptureSize)
                                  throws java.io.IOException
Execute specified command or process and returns immidiately even before the command finished.

Parameters:
commandline - - array containing the command to call and its arguments, see Runtime.exec for more description
environment - - array containing the environment for the process or just null to inherit environment, see Runtime.exec for more description
workingDir - - current working directory for the process or just null to inherit from parent see Runtime.exec for more description
bCapture - - if true then the output and error will be captured (carefull about memory) and can be read
lMaxCaptureSize - - maximal size of EACH output to be held in memory.
Returns:
Object[] - index 0 - Process object for the executed process - index 1 - StreamGobbler for the output stream - index 2 - StreamGobbler for the error stream
Throws:
java.io.IOException - - error in function


Copyright © 2003 - 2006 OpenSubsystems s.r.o.