Executes a system command. When the os attribute is specified, then the command is only executed when Ant is run on one of the specified operating systems.
Attribute | Description | Required |
command | the command to execute with all command line
arguments. deprecated, use executable and nested
<arg> elements instead. |
Exactly one of the two. |
executable | the command to execute without any command line arguments. | |
dir | the directory in which the command should be executed. | No |
os | list of Operating Systems on which the command may be executed. If the current OS's name is contained in this list, the command will be executed. The OS's name is determined by the Java Virtual machine and is set in the "os.name" system property. | No |
output | the file to which the output of the command should be redirected. | No |
append | whether output should be appended to or overwrite an existing file. Defaults to false. | No |
outputproperty | the name of a property in which the output of the command should be stored. | No |
resultproperty | the name of a property in which the return code of the command should be stored. Only of interest if failonerror=false | No |
timeout | Stop the command if it doesn't finish within the specified time (given in milliseconds). | No |
failonerror | Stop the buildprocess if the command exits with a returncode other than 0. Defaults to false | No |
newenvironment | Do not propagate old environment when new environment variables are specified. | No, default is false |
vmlauncher | Run command using the Java VM's execution facilities where available. If set to false the underlying OS's shell, either directly or through the antRun scripts, will be used. Under some operating systems, this gives access to facilities not normally available through the VM including, under Windows, being able to execute scripts, rather than their associated interpreter. | No, default is true |
<exec dir="${src}" executable="cmd.exe" os="Windows 2000" output="dir.txt"> <arg line="/c dir"/> </exec>
Command line arguments should be specified as nested
<arg>
elements. See Command line arguments.
It is possible to specify environment variables to pass to the
system command via nested <env>
elements.
Attribute | Description | Required |
key | The name of the environment variable. | Yes |
value | The literal value for the environment variable. | Exactly one of these. |
path | The value for a PATH like environment variable. You can use ; or : as path separators and Ant will convert it to the platform's local conventions. | |
file | The value for the environment variable. Will be replaced by the absolute filename of the file by Ant. |
<exec executable="emacs" > <env key="DISPLAY" value=":1.0"/> </exec>
starts emacs
on display 1 of the X Window System.
<exec ... > <env key="PATH" path="${java.library.path}:${basedir}/bin"/> </exec>
adds ${basedir}/bin
to the PATH
of the
system command.
Note: Although it may work for you to specify arguments using a simple arg-element and separate them by spaces it may fail if you switch to a newer version of the JDK. JDK < 1.2 will pass these as separate arguments to the program you are calling, JDK >= 1.2 will pass them as a single argument and cause most calls to fail.
Note2: If you are using Ant on Windows and a new DOS-Window pops up for every command which is executed this may be a problem of the JDK you are using. This problem may occur with all JDK's < 1.2.
Timeouts: If a timeout is specified, when it is reached the sub process is killed and a message printed to the log. The return value of the execution will be "-1", which will halt the build if failonerror=true, but be ignored otherwise.
Copyright © 2001-2002 Apache Software Foundation. All rights Reserved.