Package org.apache.tools.ant.taskdefs
Class Execute
- java.lang.Object
- 
- org.apache.tools.ant.taskdefs.Execute
 
- 
 public class Execute extends java.lang.ObjectRuns an external program.- Since:
- Ant 1.2
 
- 
- 
Field SummaryFields Modifier and Type Field Description static intINVALIDInvalid exit code.
 - 
Constructor SummaryConstructors Constructor Description Execute()Creates a new execute object usingPumpStreamHandlerfor stream handling.Execute(ExecuteStreamHandler streamHandler)Creates a new execute object.Execute(ExecuteStreamHandler streamHandler, ExecuteWatchdog watchdog)Creates a new execute object.
 - 
Method SummaryModifier and Type Method Description static voidcloseStreams(java.lang.Process process)Close the streams belonging to the given Process.intexecute()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<java.lang.String,java.lang.String>getEnvironmentVariables()Find the list of environment variables for this process.intgetExitValue()Query the exit value of the process.static java.util.Vector<java.lang.String>getProcEnvironment()Deprecated.use #getEnvironmentVariables insteadjava.io.FilegetWorkingDirectory()Return the working directory.booleanisFailure()Did this execute return in a failure.static booleanisFailure(int exitValue)Checks whetherexitValuesignals a failure on the current system (OS specific).booleankilledProcess()Test for an untimely death of the process.static java.lang.Processlaunch(Project project, java.lang.String[] command, java.lang.String[] env, java.io.File dir, boolean useVM)Creates a process that runs a command.static voidrunCommand(Task task, java.lang.String... cmdline)A utility method that runs an external command.voidsetAntRun(Project project)Set the name of the antRun script using the project's value.voidsetCommandline(java.lang.String[] commandline)Sets the commandline of the subprocess to launch.voidsetEnvironment(java.lang.String[] env)Sets the environment variables for the subprocess to launch.protected voidsetExitValue(int value)Set the exit value.voidsetNewenvironment(boolean newenv)Set whether to propagate the default environment or not.voidsetSpawn(boolean spawn)Deprecated.voidsetStreamHandler(ExecuteStreamHandler streamHandler)Set the stream handler to use.voidsetVMLauncher(boolean useVMLauncher)Launch this execution through the VM, where possible, rather than through the OS's shell.voidsetWorkingDirectory(java.io.File wd)Sets the working directory of the process to execute.voidspawn()Starts a process defined by the command line.static java.lang.StringtoString(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 voidwaitFor(java.lang.Process process)Wait for a given process.
 
- 
- 
- 
Field Detail- 
INVALIDpublic static final int INVALID Invalid exit code. set toInteger.MAX_VALUE- See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
Executepublic Execute() Creates a new execute object usingPumpStreamHandlerfor stream handling.
 - 
Executepublic Execute(ExecuteStreamHandler streamHandler) Creates a new execute object.- Parameters:
- streamHandler- the stream handler used to handle the input and output streams of the subprocess.
 
 - 
Executepublic 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- nullto disable a timeout for the subprocess.
 
 
- 
 - 
Method Detail- 
setSpawn@Deprecated public void setSpawn(boolean spawn) Deprecated.Set whether or not you want the process to be spawned. Default is not spawned.- Parameters:
- 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 accordingly
- Since:
- Ant 1.6
 
 - 
getEnvironmentVariablespublic static java.util.Map<java.lang.String,java.lang.String> getEnvironmentVariables() Find the list of environment variables for this process.- Returns:
- a map containing the environment variables.
- Since:
- Ant 1.8.2
 
 - 
getProcEnvironment@Deprecated public static java.util.Vector<java.lang.String> getProcEnvironment() Deprecated.use #getEnvironmentVariables insteadFind the list of environment variables for this process.- Returns:
- a vector containing the environment variables. The vector elements are strings formatted like variable = value.
 
 - 
toStringpublic 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.- Parameters:
- bos- the output stream that one wants to read.
- Returns:
- the output stream as a string, read with special encodings in the case of z/os and os/400.
- Since:
- Ant 1.5
 
 - 
setStreamHandlerpublic void setStreamHandler(ExecuteStreamHandler streamHandler) Set the stream handler to use.- Parameters:
- streamHandler- ExecuteStreamHandler.
- Since:
- Ant 1.6
 
 - 
getCommandlinepublic java.lang.String[] getCommandline() Returns the commandline used to create a subprocess.- Returns:
- the commandline used to create a subprocess.
 
 - 
setCommandlinepublic void setCommandline(java.lang.String[] commandline) Sets the commandline of the subprocess to launch.- Parameters:
- commandline- the commandline of the subprocess to launch.
 
 - 
setNewenvironmentpublic void setNewenvironment(boolean newenv) Set whether to propagate the default environment or not.- Parameters:
- newenv- whether to propagate the process environment.
 
 - 
getEnvironmentpublic java.lang.String[] getEnvironment() Returns the environment used to create a subprocess.- Returns:
- the environment used to create a subprocess.
 
 - 
setEnvironmentpublic void setEnvironment(java.lang.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.
 
 - 
setWorkingDirectorypublic void setWorkingDirectory(java.io.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.
 
 - 
getWorkingDirectorypublic java.io.File getWorkingDirectory() Return the working directory.- Returns:
- the directory as a File.
- Since:
- Ant 1.7
 
 - 
setAntRunpublic void setAntRun(Project project) throws BuildException Set the name of the antRun script using the project's value.- Parameters:
- project- the current project.
- Throws:
- BuildException- not clear when it is going to throw an exception, but it is the method's signature.
 
 - 
setVMLauncherpublic void setVMLauncher(boolean useVMLauncher) Launch this execution through the VM, where possible, rather than through the OS's shell. In some cases and operating systems using the shell will allow the shell to perform additional processing such as associating an executable with a script, etc.- Parameters:
- useVMLauncher- true if exec should launch through the VM, false if the shell should be used to launch the command.
 
 - 
launchpublic 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 Creates a process that runs a command.- Parameters:
- 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.
- Returns:
- the process started.
- Throws:
- java.io.IOException- forwarded from the particular launcher used.
- Since:
- Ant 1.5
 
 - 
executepublic int execute() throws java.io.IOExceptionRuns a process defined by the command line and returns its exit status.- Returns:
- the exit status of the subprocess or INVALID.
- Throws:
- java.io.IOException- The exception is thrown, if launching of the subprocess failed.
 
 - 
spawnpublic void spawn() throws java.io.IOExceptionStarts a process defined by the command line. Ant will not wait for this process, nor log its output.- Throws:
- java.io.IOException- The exception is thrown, if launching of the subprocess failed.
- Since:
- Ant 1.6
 
 - 
waitForprotected void waitFor(java.lang.Process process) Wait for a given process.- Parameters:
- process- the process one wants to wait for.
 
 - 
setExitValueprotected void setExitValue(int value) Set the exit value.- Parameters:
- value- exit value of the process.
 
 - 
getExitValuepublic int getExitValue() Query the exit value of the process.- Returns:
- the exit value or Execute.INVALID if no exit value has been received.
 
 - 
isFailurepublic static boolean isFailure(int exitValue) Checks whetherexitValuesignals 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. - Parameters:
- exitValue- the exit value (return code) to be checked.
- Returns:
- trueif- exitValuesignals a failure.
 
 - 
isFailurepublic boolean isFailure() Did this execute return in a failure.- Returns:
- true if and only if the exit code is interpreted as a failure
- Since:
- Ant1.7
- See Also:
- isFailure(int)
 
 - 
killedProcesspublic boolean killedProcess() Test for an untimely death of the process.- Returns:
- true if a watchdog had to kill the process.
- Since:
- Ant 1.5
 
 - 
runCommandpublic static void runCommand(Task task, java.lang.String... cmdline) throws BuildException A utility method that runs an external command. Writes the output and error streams of the command to the project log.- Parameters:
- task- The task that the command is part of. Used for logging
- cmdline- The command to execute.
- Throws:
- BuildException- if the command does not exit successfully.
 
 - 
closeStreamspublic static void closeStreams(java.lang.Process process) Close the streams belonging to the given Process.- Parameters:
- process- the- Process.
 
 
- 
 
-