Question

Today I had to add a task to an Apache Ant file. The command line should have been something like

myprogram --param1 --param2 path\somefile 2> path\logfile

The problem with this was that if I used something like the following for this

<exec executable="$(myprogram)"
  <arg value="--param1">
  <arg value="--param2">
  <arg path="$(somefile)">
  <arg value="2>">
  <arg path="$(logfile)">
</exec>

all arguments were quoted, so the command looked like this:

myprogram "--param1" "--param2" "path\somefile" "2>" "path\logfile"

which is not bad and especially nice if you have spaces in your files/path, but destroys the pipe to the logfile (instead, the program thinks there are two additional file arguments "2>" and "path\logfile").

I worked around this by calling a batch script instead that only wants the files as parameters, but I wondered: Is it possible to do this without such a workaround?

Was it helpful?

Solution

When you run "myprogram --param1 --param2 path\somefile 2> path\logfile", the arguments to your program end at "2>". File redirection is an operation of your shell, which isn't being used from within ant. If you look at the docs for the ant exec task, you'll see that it supports redirection via the output attribute.

OTHER TIPS

Have you tried <arg line="..." />?

The ant exec task has an output parameter where you could specify the log file without requiring the command line piping, combined with the parameter append to determine if the output file should be overwritten or appended to.

I had an equal problem as the topic starter did. On a java execution command line I needed to add source files as separate arguments, not as one argument with quotes around them. I used the <arg value="..." /> tag, but using the <arg line="..." /> as nullptr suggested solved my problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top