## Apply/ExecOn

The name `execon` is deprecated and only kept for backwards compatibility.

### Description

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.

The files and/or directories of a number of FileSets are passed as arguments to the system command.

If you specify a nested mapper and the dest attribute, the timestamp of each source file is compared to the timestamp of a target file which is defined by the nested mapper element and searched for in the given dest.

At least one fileset is required, and you must not specify more than one mapper.

### Parameters

Attribute | Description | Required
executable | the command to execute without any command line arguments. | Yes
dest | the directory where the <apply> expects the target files will be placed by the command, when it is executed. | Yes, if you specify a nested mapper
dir | the directory in which the command should be executed. | No
relative | whether the filenames should be passed on the command line as absolute or relative pathnames (relative to the base directory of the corresponding fileset for source files or the dest attribute for target files). | No, default is false
os | list of Operating Systems on which the command may be executed. | 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. If you set parallel to false, you will probably want to set this one to true. | 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. If you set parallel to false, only the result of the first execution will be stored. | 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. | No
failifexecutionfails | Stop the build if we can't start the program. Defaults to true. | No
skipemptyfilesets | Don't run the command, if no source files have been found or are newer than their corresponding target files. | No, default is false
parallel | Run the command only once, appending all files as arguments. If false, command will be executed once for every file. Defaults to false. | No
type | One of file, dir or both. If set to file, only the names of plain files will be sent to the command. If set to dir, only the names of directories are considered. | No, default is file
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. If you want to specify the name of the executable as a relative path to the directory given by the dir attribute, it may become necessary to set vmlauncher to false as well. | No, default is true

### Parameters specified as nested elements

#### fileset

You can use any number of nested `<fileset>` elements to define the files for this task and refer to `<fileset>`s defined elsewhere.

#### arg

Command line arguments should be specified as nested `<arg>` elements. See Command line arguments.

#### srcfile

By default the file names of the source files will be added to the end of the command line. If you need to place it somewhere different, use a nested `<srcfile>` element between your `<arg>` elements to mark the insertion point.

#### targetfile

`<targetfile>` is similar to `<srcfile>` and marks the position of the target filename on the command line. If omitted, the target filenames will not be added to the command line at all. This element can only be specified, if you also define a nested mapper and the dest attribute.

#### env

It is possible to specify environment variables to pass to the system command via nested `<env>` elements. See the description in the section about exec

### Examples

>     <apply executable="ls">
>       <arg value="-l"/>
>       <fileset dir="/tmp">
>         <patternset>
>           <exclude name="**/*.txt"/>
>         </patternset>
>       </fileset>
>       <fileset refid="other.files"/>
>     </apply>

invokes `ls -l`, adding the absolute filenames of all files below `/tmp` not ending in `.txt` and all files of the FileSet with `id` `other.files` to the command line.

>     <apply executable="somecommand" parallel="false">
>       <arg value="arg1"/>
>       <srcfile/>
>       <arg value="arg2"/>
>       <fileset dir="/tmp"/>
>     </apply>

invokes `somecommand arg1 SOURCEFILENAME arg2` for each file in `/tmp` replacing SOURCEFILENAME with the absolute filename of each file in turn. If `parallel` had been set to true, SOURCEFILENAME would be replaced with the absolute filenames of all files separated by spaces.

>     <apply executable="cc" dest="src/C" parallel="false">
>       <arg value="-c"/>
>       <arg value="-o"/>
>       <targetfile/>
>       <srcfile/>
>       <fileset dir="src/C" includes="*.c"/>
>       <mapper type="glob" from="*.c" to="*.o"/>
>     </apply>

invokes `cc -c -o TARGETFILE SOURCEFILE` for each `.c` file that is newer than the corresponding `.o`, replacing TARGETFILE with the absolute filename of the `.o` and SOURCEFILE with the absolute name of the `.c` file.

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