bash shell:
./mimic_cmd "startDaemon()"
Corresponding Ant code:
<exec failonerror="true" executable="/bin/mimic_cmd">
<arg value='"startDaemon()"' />
</exec>
- Does the Ant code exactly represent the above command at the bash shell? Based on the debug info, it looks like it:
[exec] Executing '/bin/mimic_cmd' with arguments: [exec] '"startDaemon()"' [exec] [exec] The ' characters around the executable and arguments are [exec] not part of the command. Execute:Java13CommandLauncher: Executing '/bin/mimic_cmd' with arguments: '"startDaemon()"' The ' characters around the executable and arguments are not part of the command.
However, the Ant code returns and exit code of 1 while the Bash shell command returns 0.
Toggling vmlauncher doesn’t help, and paths are all correct.
The same Ant code works on windows with the resulting debug output:
[exec] Executing 'C:\bin\mimic_cmd' with arguments: [exec] '"startDaemon()"' [exec] [exec] The ' characters around the executable and arguments are [exec] not part of the command. Execute:Java13CommandLauncher: Executing 'C:\bin\mimic_cmd' with arguments: '"startDaemon()"' The ' characters around the executable and arguments are not part of the command.
Can you tell us what
mimic_cmdis? (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:…actually is:
…or, for illustrative purposes:
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
execing ofsh -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 spawnmimic_cmdit 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 casemimic_cmdfinds 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.EXEis 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’CreateProcesswhich does not have the notion ofargv[], leaving it up to each program to intepretlpCommandLinein whichever way it sees fit; some will get rid of the quotes for you, but that behaviour is extremely inconsistent, e.g. issueecho "bla"on theCMD.EXEprompt to see whatCMD.EXE‘s builtins think about quoting.) Again, in your case the round parens()have no meaning forCMD.EXEso you don’t need them even when typing the command at a command prompt. As for ANT, on Windows as on *nix platforms, it spwansmimic_cmdviaCreateProcessnotCMD.EXEso you don’t really want to quote anything.