Running Native Programs in Ant

native-programs-in-ant

native-programs-in-ant

Running Native Programs in Ant

Ant, while extremely powerful and flexible, can’t always offer everything you want to do. If this

is the case, you can use the <exec> task, which can run any command-line program.

 The <exec> Task’s Attributes

Attribute Description
appends Sets whether to append the output to the end of a file or overwrite the contents of the file (used in conjunction with output). The default is false.
dir The directory from where the program will be run. The default is null.
error The file to which you want to redirect error messages. The default is the setting in output.
Errorproperty The property where Ant will store error messages. The default is blank.
Executable The command you want to execute. This should be the name of the command and should not be accompanied by any arguments. You specify them with nested <arg> elements. This attribute is required.
failifexecutionfails Tells Ant whether to stop the build if the command fails to start at all. The default is true.
failonerror Tells Ant whether to stop the build if the command exits with a return code other than 0. The default is false.
input The name of a file that will be the input to this command. You can specify only one of input and inputstring. The default is standard input from the console. In addition, you cannot obtain standard input if you set spawn to true.
inputstring A string that will be the input to this command. You can specify only one of input and inputstring. The default is standard input from the console. In addition, you cannot obtain standard input if you set spawn to true.
logError Tells Ant to write error messages to the Ant log files. The error messages will not appear in any output location that you have set. Ant ignores this attribute if you set error or errorproperty. The default is false.
Newenvironment Tells the program to ignore old environment variables if new ones are specified. The default is false.
os Ant will execute the command only if it is running on an operating system in this list. Ant uses String.indexOf() < 0 to see whether the operating system matches anything in this list, so you can specify the operating systems in any format you like, even a continuous string with no separators. The default is to always run the command.
output The file to which you want to redirect output. The default is standard out.
outputproperty The property where Ant will store the output of this command (including error messages unless otherwise redirected). The default is blank.
resolveexecutable Tells Ant to locate the executable in the project’s base directory or the directory specified by dir. The default is false (use the user’s current path).
resultproperty The property where Ant will store the return code of this command. You can use this attribute only if failonerror is false (you’ll find details about this after the table). The default is blank.
searchpath Tells Ant to use the system PATH environment variable to find the command. The default is false.
spawn Tells Ant to start a process that will live after the Ant process has finished. You can’t use error, input, output, or result. The default is false.
timeout The time in milliseconds that Ant should wait before stopping this command. The default is null.
vmlauncher Tells Ant whether to use the JVM’s execution functionality instead of the operating system’s shell. The default is true.