public class Execute
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
INVALID
Invalid exit code.
|
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
static void |
closeStreams(java.lang.Process process)
Close the streams belonging to the given Process.
|
int |
execute()
Runs a process defined by the command line and returns its exit status.
|
java.lang.String[] |
getCommandline()
Returns the commandline used to create a subprocess.
|
java.lang.String[] |
getEnvironment()
Returns the environment used to create a subprocess.
|
static java.util.Map |
getEnvironmentVariables()
Find the list of environment variables for this process.
|
int |
getExitValue()
Query the exit value of the process.
|
static java.util.Vector |
getProcEnvironment()
Deprecated.
use #getEnvironmentVariables instead
|
java.io.File |
getWorkingDirectory()
Return the working directory.
|
boolean |
isFailure()
Did this execute return in a failure.
|
static boolean |
isFailure(int exitValue)
Checks whether
exitValue signals a failure on the current
system (OS specific). |
boolean |
killedProcess()
Test for an untimely death of the process.
|
static java.lang.Process |
launch(Project project,
java.lang.String[] command,
java.lang.String[] env,
java.io.File dir,
boolean useVM)
Creates a process that runs a command.
|
static void |
runCommand(Task task,
java.lang.String[] cmdline)
A utility method that runs an external command.
|
void |
setAntRun(Project project)
Set the name of the antRun script using the project's value.
|
void |
setCommandline(java.lang.String[] commandline)
Sets the commandline of the subprocess to launch.
|
void |
setEnvironment(java.lang.String[] env)
Sets the environment variables for the subprocess to launch.
|
protected void |
setExitValue(int value)
Set the exit value.
|
void |
setNewenvironment(boolean newenv)
Set whether to propagate the default environment or not.
|
void |
setSpawn(boolean spawn)
Deprecated.
|
void |
setStreamHandler(ExecuteStreamHandler streamHandler)
Set the stream handler to use.
|
void |
setVMLauncher(boolean useVMLauncher)
Launch this execution through the VM, where possible, rather than through
the OS's shell.
|
void |
setWorkingDirectory(java.io.File wd)
Sets the working directory of the process to execute.
|
void |
spawn()
Starts a process defined by the command line.
|
static java.lang.String |
toString(java.io.ByteArrayOutputStream bos)
ByteArrayOutputStream#toString doesn't seem to work reliably on
OS/390, at least not the way we use it in the execution
context.
|
protected void |
waitFor(java.lang.Process process)
Wait for a given process.
|
public static final int INVALID
Integer.MAX_VALUE
public Execute()
PumpStreamHandler
for
stream handling.public Execute(ExecuteStreamHandler streamHandler)
streamHandler
- the stream handler used to handle the input and
output streams of the subprocess.public Execute(ExecuteStreamHandler streamHandler, ExecuteWatchdog watchdog)
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.public void setSpawn(boolean spawn)
spawn
- if true you do not want Ant
to wait for the end of the process.
Has no influence in here, the calling task contains
and acts accordinglypublic static java.util.Map getEnvironmentVariables()
public static java.util.Vector getProcEnvironment()
public static java.lang.String toString(java.io.ByteArrayOutputStream bos)
bos
- the output stream that one wants to read.public void setStreamHandler(ExecuteStreamHandler streamHandler)
streamHandler
- ExecuteStreamHandler.public java.lang.String[] getCommandline()
public void setCommandline(java.lang.String[] commandline)
commandline
- the commandline of the subprocess to launch.public void setNewenvironment(boolean newenv)
newenv
- whether to propagate the process environment.public java.lang.String[] getEnvironment()
public void setEnvironment(java.lang.String[] env)
env
- array of Strings, each element of which has
an environment variable settings in format key=value.public void setWorkingDirectory(java.io.File wd)
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.
wd
- the working directory of the process.public java.io.File getWorkingDirectory()
public void setAntRun(Project project) throws BuildException
project
- the current project.BuildException
- not clear when it is going to throw an exception, but
it is the method's signature.public void setVMLauncher(boolean useVMLauncher)
useVMLauncher
- true if exec should launch through the VM,
false if the shell should be used to launch the
command.public static java.lang.Process launch(Project project, java.lang.String[] command, java.lang.String[] env, java.io.File dir, boolean useVM) throws java.io.IOException
project
- the Project, only used for logging purposes, may be null.command
- the command to run.env
- the environment for the command.dir
- the working directory for the command.useVM
- use the built-in exec command for JDK 1.3 if available.java.io.IOException
- forwarded from the particular launcher used.public int execute() throws java.io.IOException
INVALID
.java.io.IOException
- The exception is thrown, if launching
of the subprocess failed.public void spawn() throws java.io.IOException
java.io.IOException
- The exception is thrown, if launching
of the subprocess failed.protected void waitFor(java.lang.Process process)
process
- the process one wants to wait for.protected void setExitValue(int value)
value
- exit value of the process.public int getExitValue()
public static boolean isFailure(int exitValue)
exitValue
signals a failure on the current
system (OS specific).
Note that this method relies on the conventions of the OS, it will return false results if the application you are running doesn't follow these conventions. One notable exception is the Java VM provided by HP for OpenVMS - it will return 0 if successful (like on any other platform), but this signals a failure on OpenVMS. So if you execute a new Java VM on OpenVMS, you cannot trust this method.
exitValue
- the exit value (return code) to be checked.true
if exitValue
signals a failure.public boolean isFailure()
isFailure(int)
public boolean killedProcess()
public static void runCommand(Task task, java.lang.String[] cmdline) throws BuildException
task
- The task that the command is part of. Used for loggingcmdline
- The command to execute.BuildException
- if the command does not exit successfully.public static void closeStreams(java.lang.Process process)
process
- the Process
.