Spring AMQP

org.springframework.util.exec
Class Execute

java.lang.Object
  extended by org.springframework.util.exec.Execute

public class Execute
extends Object

Runs an external program. Derived from ant exec task. All the 'backward compat with jdk1.1, 1.2' removed. Since jdk1.3 supports working dir, no need for scripts. All ant-specific code has been removed as well, this is a completely independent component.

Author:
thomas.haas@softwired-inc.com, Costin Leau

Field Summary
static int INVALID
          Invalid exit code.
 
Constructor Summary
Execute()
          Creates a new execute object using PumpStreamHandler for stream handling.
Execute(ExecuteStreamHandler streamHandler)
          Creates a new execute object.
Execute(ExecuteStreamHandler streamHandler, ExecuteWatchdog watchdog)
          Creates a new execute object.
 
Method Summary
 int execute()
          Runs a process defined by the command line and returns its exit status.
static int execute(Vector<String> envVars, String cmd, File baseDir)
           
static int execute(Vector<String> envVars, Vector<String> cmd, File baseDir)
           
static int execute(Vector<String> envVars, Vector<String> cmd, File baseDir, int timeToWait)
          Wrapper for common execution patterns
 String[] getCommandline()
          Returns the commandline used to create a subprocess.
 String getCommandLineString()
           
 String[] getEnvironment()
          Returns the environment used to create a subprocess.
 int getExitValue()
          query the exit value of the process.
static Vector<String> getProcEnvironment()
          Find the list of environment variables for this process.
 void kill()
           
 void setCommandline(String[] commandline)
          Sets the commandline of the subprocess to launch.
 void setEnvironment(String[] env)
          Sets the environment variables for the subprocess to launch.
protected  void setExitValue(int value)
           
 void setNewenvironment(boolean newenv)
          Set whether to propagate the default environment or not.
 void setWorkingDirectory(File wd)
          Sets the working directory of the process to execute.
protected  void waitFor(Process process)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INVALID

public static final int INVALID
Invalid exit code.

See Also:
Constant Field Values
Constructor Detail

Execute

public Execute()
Creates a new execute object using PumpStreamHandler for stream handling.


Execute

public Execute(ExecuteStreamHandler streamHandler)
Creates a new execute object.

Parameters:
streamHandler - the stream handler used to handle the input and output streams of the subprocess.

Execute

public Execute(ExecuteStreamHandler streamHandler,
               ExecuteWatchdog watchdog)
Creates a new execute object.

Parameters:
streamHandler - the stream handler used to handle the input and output streams of the subprocess.
watchdog - a watchdog for the subprocess or null to to disable a timeout for the subprocess.
Method Detail

getProcEnvironment

public static Vector<String> getProcEnvironment()
Find the list of environment variables for this process.


getCommandline

public String[] getCommandline()
Returns the commandline used to create a subprocess.

Returns:
the commandline used to create a subprocess

getCommandLineString

public String getCommandLineString()

setCommandline

public void setCommandline(String[] commandline)
Sets the commandline of the subprocess to launch.

Parameters:
commandline - the commandline of the subprocess to launch

setNewenvironment

public void setNewenvironment(boolean newenv)
Set whether to propagate the default environment or not.

Parameters:
newenv - whether to propagate the process environment.

getEnvironment

public String[] getEnvironment()
Returns the environment used to create a subprocess.

Returns:
the environment used to create a subprocess

setEnvironment

public void setEnvironment(String[] env)
Sets the environment variables for the subprocess to launch.

Parameters:
env - array of Strings, each element of which has an environment variable settings in format key=value

setWorkingDirectory

public void setWorkingDirectory(File wd)
Sets the working directory of the process to execute.

This is emulated using the antRun scripts unless the OS is Windows NT in which case a cmd.exe is spawned, or MRJ and setting user.dir works, or JDK 1.3 and there is official support in java.lang.Runtime.

Parameters:
wd - the working directory of the process.

execute

public int execute()
            throws Exception
Runs a process defined by the command line and returns its exit status.

Returns:
the exit status of the subprocess or INVALID
Throws:
Exception - if launching of the subprocess failed

kill

public void kill()

waitFor

protected void waitFor(Process process)

setExitValue

protected void setExitValue(int value)

getExitValue

public int getExitValue()
query the exit value of the process.

Returns:
the exit value, 1 if the process was killed, or Project.INVALID if no exit value has been received

execute

public static int execute(Vector<String> envVars,
                          String cmd,
                          File baseDir)

execute

public static int execute(Vector<String> envVars,
                          Vector<String> cmd,
                          File baseDir)

execute

public static int execute(Vector<String> envVars,
                          Vector<String> cmd,
                          File baseDir,
                          int timeToWait)
Wrapper for common execution patterns

Parameters:
envVars - Environment variables to execute with (optional)
cmd - a vector of the commands to execute
baseDir - the base directory to run from (optional)
timeToWait - milliseconds to wait for completion

Spring AMQP

Copyright © 2011. All Rights Reserved.