I ran into a little gotcha with the Ant exec the other day, and thought I’d share it with you. If you’re familiar with the Unix shell (or even the Windows command interpreter), you’ll realize that
$ non_existent_command > foo.txt
will result in zero bytes of output in foo.txt. There’ll be an accompanying message to standard error to the effect that the command non_existent_command doesn’t exist.
The ant exec task behaves a little differently. This seemingly similar example
<exec command="non_existent_command" output="foo.txt" />
will give you an error message, but will leave the contents of foo.txt unchanged.
In may case, the results of the previous successful run led me astray. The fact that I was examining the results of the output via a web interface, so didn’t have access to the file modification timestamp, didn’t help, either.
This highlights a little beef I have with Ant: a number of responsibilities, like writing to output files, seem to be deferred to the task implementation. This opens the door to inconsistencies in edge cases like this.
The moral: look (at the modification timestamp of your output files) before you leap!