B.4 ApplyTask

Applies a system command on each resource of the specified resource collection.

When the os attribute is specified, then the command is only executed when run on one of the specified operating systems.

The files of a number of Resource Collections – including but not restricted to FileSets, FileLists or DirSets – are passed as arguments to the system command.

Table B.5: Attributes

NameTypeDescriptionDefaultRequiredAlias
executableStringThe command to execute without any command line arguments.n/aYes 
dirStringThe directory the command is to be executed in.n/aNo 
outputStringWhere to direct stdout.n/aNo 
errorStringWhere to direct stderr.n/aNo 
osStringOnly execute if the Appendix A, Fact Sheet property contains specified text.n/aNo 
escapeBooleanEscape shell metacharacters before execution. Setting this to true will enable the escape precaution.falseNo 
passthruBooleanWhether to use PHP's passthru() function instead of exec().falseNo 
spawnBooleanWhether to spawn unix programs to the background, redirecting stdout (output will not be logged by Phing).falseNo 
returnPropertyStringProperty name to set return value to from the execution.n/aNo 
outputPropertyStringProperty name to set output value to from the execution.n/aNo 
checkreturnBooleanWhether to check the return code of the execution, throws a BuildException when returncode != 0.falseNofailonerror
appendBooleanWhether output (and error) should be appended to or overwrite an existing file. If you set parallel to false, you will probably want to set this one to true.falseNo 
parallelBooleanRun the command only once, appending all files as arguments. If false, command will be executed once for every file.falseNo 
addsourcefileBooleanWhether source file name(s) should be added to the end of command-line automatically. If you need to place it somewhere different, use a nested <srcfile> element between your <arg> elements to mark the insertion point.trueNo 
relativeBooleanWhether the filenames should be passed on the command line as relative pathnames (relative to the base directory of the corresponding fileset/list for source files).falseNo 
forwardslashBooleanWhether the file names should be passed with forward slashes even if the operating system requires other file separator.falseNo 
maxparallelIntegerLimit the amount of parallelism by passing at most this many sourcefiles at once. Set it to <= 0 for unlimited.0No 

B.4.1 Examples

<!-- Invokes somecommand arg1 SOURCEFILENAME arg2 for each file in /tmp -->
<apply executable="somecommand" parallel="false">
  <arg value="arg1"/>
  <srcfile/>
  <arg value="arg2"/>
  <fileset dir="/tmp"/>
</apply>


<!-- List all the .conf files of "/etc" to the "out.log" file. -->
<apply executable="ls" output="/tmp/out.log" append="true" >
  <arg value="-alh" />
  <fileset dir="/etc" >
    <include name="*.conf" />
  </fileset>
</apply>
            

B.4.2 Supported Nested Tags

  • arg

    Table B.6: Attributes

    NameTypeDescriptionDefaultRequired
    valueStringA single command-line argument; can contain space characters.n/aOne of these
    fileStringThe name of a file as a single command-line argument; will be replaced with the absolute filename of the file.n/a
    pathStringA string that will be treated as a path-like string as a single command-line argument; you can use ; or : as path separators and Phing will convert it to the platform's local conventions.n/a
    lineStringA space-delimited list of command-line arguments.n/a


  • fileset

  • filelist

  • dirset

  • srcfile