Exec command in Ant only executes first command

162 views Asked by At

I want to list the permission of every script in directory dir/bin. But the below command only runs "ls" in the directory where the script is with below code rather than every script in dir/bin. Since script.xml is there in maindir, it just does a ls inside maindir.

There are 2 problems:

  1. Performing ls -l & not just the 1st command in the line
  2. Performing ls -l in right directory instead of directory where the script is.

The directory structure:

   - maindir
     - dir
        -bin
          -test.sh
          -con.py
     - script.xml

Below code is called "script.xml":

<foreach param="dirSc" in="dir/bin">
    <exec executable="/bin/sh"
        resultproperty="returncode"     
        output="dir/output.txt">
        <arg value="-c" />
        <arg line="ls -l ${dirSc}" />
   </exec>
<foreach>
1

There are 1 answers

0
Mark O'Connor On BEST ANSWER

I suggest using the apply task to run commands against a series of files.

Example

├── build.xml
└── dir
    └── bin
        ├── con.py
        └── test.sh

Produces the following output

scan:
    [apply] -rw-r--r-- 1 mark mark 1 Jun 23 23:30 ../dir/bin/con.py
    [apply] -rw-r--r-- 1 mark mark 1 Jun 23 23:29 ../dir/bin/test.sh

build.xml

<project name="demo" default="scan">

  <target name="scan">
    <apply executable="ls">
      <arg value="-l"/>
      <fileset dir="dir"/>
    </apply>
  </target>

</project>