I’m trying to run the following command using the ‘exec’ task in Ant:
ls -l /foo/bar | wc -l
Currently, I have my exec looking like this:
<exec executable="ls" outputproperty="noOfFiles">
<arg value="-l" />
<arg value="/foo/bar" />
<arg value="|" />
<arg value="wc" />
<arg value="-l" />
</exec>
The ‘ls’ command looks to be working but it’s having a hard time piping the output to ‘wc’. Any suggestions?
If you use
sh -cas Aaron suggests, you can pass the whole pipeline as a single arg, effectively doing:If you use separate args, they are consumed by sh, not passed through to ls (hence you see just the current directory).
Note that on my system,
ls -lincludes a total as well as a list of the files found, which means the count shown is one more than the number of files. So suggest: