Can you tell us what mimic_cmd
is? (Is it an ELF executable, is it a script -- and if so, what is its contents?)
You don't need nor want the double-quotes inside your ANT XML attributes (incidentally, for it to be well-formed XML you should have written them as "
not "
, but that changes nothing with respect to this discussion) unless your executable expects them. The corresponding ANT code for either of the following (100% equivalent) shell command lines:
./mimic_cmd "startDaemon()"
./mimic_cmd 'startDaemon()'
./mimic_cmd startDaemon\(\)
./mimic_cmd startDaemon"()"
./mimic_cmd startDaemon'()'
...actually is:
<exec failonerror="true" executable="/bin/mimic_cmd">
<arg value="startDaemon()" />
</exec>
...or, for illustrative purposes:
<!-- spawn a shell with your original command line -->
<exec failonerror="true" executable="/bin/sh">
<arg value="-c" />
<arg value="/bin/mimic_cmd "startDaemon()"" />
</exec>
Why that is so is longwinded to explain; suffices to say that, in your specific case, the only time when you'd have to use double quotes would be when ultimately issuing the command via a *nix shell (either interactively or as part of another script or programatically via the exec
ing of sh -c
), and only in order for that shell not to think that the round parens ()
have special meaning. By the time the shell would in turn spawn mimic_cmd
it would have already stripped the double quotes (and substituted backslash-escaped sequences etc. -- see how a *nix shell parses its command line) ANT does not run your command via the shell but rather executes it directly, so in this case mimic_cmd
finds itself with a bunch of double quotes on its hand which it apparently doesn't know how to handle.
You essentially have to think of it as replacing all forms of shell quoting and escaping with XML escaping and breaing down into <arg/>
tags.
Windows' CMD.EXE
is special in the sense that, unline *nix shells, it does minimal parsing (and generally does not care about double quotes in program arguments), leaving it up to the program to figure out what you meant by quoting. (This is actually a hard limitation of Windows' CreateProcess
which does not have the notion of argv[]
, leaving it up to each program to intepret lpCommandLine
in whichever way it sees fit; some will get rid of the quotes for you, but that behaviour is extremely inconsistent, e.g. issue echo "bla"
on the CMD.EXE
prompt to see what CMD.EXE
's builtins think about quoting.) Again, in your case the round parens ()
have no meaning for CMD.EXE
so you don't need them even when typing the command at a command prompt. As for ANT, on Windows as on *nix platforms, it spwans mimic_cmd
via CreateProcess
not CMD.EXE
so you don't really want to quote anything.