Question

The following ANT exec tag does not behave as expected.

<exec executable="c:\scratch\test.cmd">
    <arg value="A,B,C"/>
</exec>

When executed, I would expect this to call text.cmd with 1 argument. However, the arg is being expanded to three separate arguments.

As per the Manual, value is supposed to pass the contents as a single argument, however, it is passed as three (one for each component of the string separated by a comma).

I tried replacing the command "," with a semicolon (;) but this does not work either. It appears as if arg's value attribute parses the supplied string as if it were a path, which it is not.

Anyone know how to the "A,B,C" to pass as one argument?

For the sake of completeness, my test.cmd file is this:

@echo off
echo Arg1: %1
echo Arg2: %2
echo Arg3: %3
echo Arg4: %4
echo Arg5: %5
echo Arg6: %6
echo Arg7: %7
echo Arg8: %8
echo Arg9: %9

and the output of the ant build is:

 [exec] Arg1: A
 [exec] Arg2: B
 [exec] Arg3: C
 [exec] Arg4:
 [exec] Arg5:
 [exec] Arg6:
 [exec] Arg7:
 [exec] Arg8:
 [exec] Arg9:
Was it helpful?

Solution

Issue has been resolved. I was so focused on the issue being in ant, that I didn't take the time to test how DOS like command lines interpret the command-line arguments.

from Window command line, I ran test.cmd a,c,b and see that the command argument was split, therefore, the issue is not related to ant. so now I just need to figure out how to force ANT to quote the arguments.

OTHER TIPS

Try:

<exec executable="c:\scratch\test.cmd">
    <arg line="A,B,C"/>
</exec>

See ant manual for description of how arguments work.

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