EXEC ARGS(值)与ANT脚本在Linux上报价 [英] EXEC args (value) with quotes on linux from ANT script

查看:187
本文介绍了EXEC ARGS(值)与ANT脚本在Linux上报价的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

bash shell中:

  ./ mimic_cmdstartDaemon()

对应ANT code:

 < EXEC failonerror =真的可执行文件=/斌/ mimic_cmd>
    < ARG值='startDaemon()/>
 < / EXEC>


  1. 是否ANT code正是重新present在bash外壳上面的命令?根据调试信息,它看起来像它:


  [执行]执行'/斌/ mimic_cmd'与参数:
 [执行]'startDaemon()'
 [执行]
 [执行]周围的可执行文件和参数的'字符
 [执行]不是命令的一部分。
 执行:Java13CommandLauncher:执行/ bin中/ mimic_cmd'与参数:
 'startDaemon()'
 周围的可执行的字符和参数不是命令的一部分。


不过,1 ANT code的回报和退出code,而Bash shell中命令返回0。

切换vmlauncher没有帮助,和路径是正确的。

同样的ANT code适用于Windows与生成的调试输出:


  [执行]执行'C:\\ BIN \\ mimic_cmd'与参数:
 [执行]'startDaemon()'
 [执行]
 [执行]周围的可执行文件和参数的'字符
 [执行]不是命令的一部分。
 执行:Java13CommandLauncher:执行'C:\\ BIN \\ mimic_cmd'与参数:
 'startDaemon()'
 周围的可执行的字符和参数不是命令的一部分。



解决方案

你能告诉我们什么 mimic_cmd 是? (它是一个ELF可执行,它是一个脚本 - ?如果是这样,什么是它的内容)

您的不需要也不想要了双引号您的ANT XML属性(内部顺便说一下,它被良好的XML,你应该写他们为&放; QUOT; 不是,但是这改变不了什么关于这个讨论),除非你的可执行希望他们相应的ANT code表示。以下两种(100%当量)shell命令行:

  ./mimic_cmdstartDaemon()
   ./mimic_cmd'startDaemon()'
   ./mimic_cmd startDaemon \\(\\)
   ./mimic_cmd startDaemon()
   ./mimic_cmd startDaemon'()'

...居然是:

 < EXEC failonerror =真的可执行文件=/斌/ mimic_cmd>
      < ARG值=startDaemon()/>
   < / EXEC>

...或者,为了说明的目的

 <! - 产卵与你原来的命令行外壳 - >
   < EXEC failonerror =真的可执行文件=/ bin / sh的>
      < ARG值= - C/>
      < ARG值=/斌/ mimic_cmd和放大器; QUOT; startDaemon()及QUOT; />
   < / EXEC>

为什么会这样被冗长的解释;足以说,在特定的情况下,唯一的时候,你不得不使用双引号是当通过一个* nix的外壳最终发出命令(通过交互或作为另一个脚本或通过<$ C编程部分$ C> EXEC 的ING SH -c ),只为了使这种壳不要以为圆括号()有特殊的意义。由当时的外壳会反过来产卵 mimic_cmd 将已经剥离了双引号(和取代的反斜杠转义序列等 - 看到的how在* nix壳解析它的命令行)ANT不通过shell中运行您的命令,而是直接执行,所以在这种情况下, mimic_cmd 发现自己与一帮其手双引号的,它显然不知道如何处理。

您基本上都认为它是替换所有形式的壳报价和XML转义和breaing成逃逸&LT; ARG /方式&gt; 标记

Windows的 CMD.EXE 在某种意义上特殊即,unline * nix的外壳,但它最小的解析(一般不关心在程序参数双引号),留给了程序找出你引述的意思。 (这实际上是Windows的一个硬限制<一个href=\"http://msdn.microsoft.com/en-us/library/ms682425%28VS.85%29.aspx\"><$c$c>CreateProcess其中没有的argv [] 的概念,离开它由每个程序INTE preT lpCommandLine 在无论怎样它认为合适;有些人会摆脱报价为你,但这种行为是非常不一致的,例如发行回声喇嘛 CMD.EXE 提示符下,看看 CMD.EXE 的建宏想引用。)同样,你的情况全面括号() CMD.EXE 因此在命令提示符下键入命令,即使你不需要他们。至于ANT,在Windows上作为* nix平台,它spwans mimic_cmd 通过的CreateProcess 不是 CMD.EXE ,所以你真的不想引用任何东西。

bash shell:

./mimic_cmd "startDaemon()"

Corresponding ANT code:

 <exec failonerror="true" executable="/bin/mimic_cmd">
    <arg value='"startDaemon()"' />
 </exec>

  1. 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_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 &quot; 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 &quot;startDaemon()&quot;" /> 
   </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 execing 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.

这篇关于EXEC ARGS(值)与ANT脚本在Linux上报价的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆