Execute (Apache Ant API)

org.apache.tools.ant.taskdefs
Class Execute


java.lang.Object

  |

  +--org.apache.tools.ant.taskdefs.Execute


public class Execute
extends java.lang.Object

Runs an external program.

Since:
Ant 1.2
Version:
$Revision: 1.43.2.5 $
Author:
thomas.haas@softwired-inc.com
, Jeff Tulley

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.
 java.lang.String[] getCommandline()
          Returns the commandline used to create a subprocess.
 java.lang.String[] getEnvironment()
          Returns the environment used to create a subprocess.
 int getExitValue()
          query the exit value of the process.
static java.util.Vector getProcEnvironment()
          Find the list of environment variables for this process.
 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)
           
 void setNewenvironment(boolean newenv)
          Set whether to propagate the default environment or not.
 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.
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)
           
 
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 java.util.Vector getProcEnvironment()
Find the list of environment variables for this process.


toString


public 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.

Since:
Ant 1.5

getCommandline


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

Returns:
the commandline used to create a subprocess

setCommandline


public void setCommandline(java.lang.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 java.lang.String[] getEnvironment()
Returns the environment used to create a subprocess.

Returns:
the environment used to create a subprocess

setEnvironment


public 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

setWorkingDirectory


public 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.

setAntRun


public void setAntRun(Project project)
               throws BuildException
Set the name of the antRun script using the project's value.

Parameters:
project - the current project.
BuildException

setVMLauncher


public 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 thge VM, false if the shell should be used to launch the command.

launch


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
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.
java.io.IOException
Since:
Ant 1.5

execute


public int execute()
            throws java.io.IOException
Runs 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

waitFor


protected void waitFor(java.lang.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

killedProcess


public boolean killedProcess()
test for an untimely death of the process

Returns:
true iff a watchdog had to kill the process
Since:
Ant 1.5

runCommand


public 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 return 0.


Copyright © 2000-2002 Apache Software Foundation. All Rights Reserved.