【发布时间】:2013-01-31 00:26:33
【问题描述】:
我正在尝试从 Ant 构建文件中运行以下命令:
sh /home/myuser/scripts/run.sh -p=8888 -z=true /home/myuser/resources/mydir
到目前为止,这是我最好的尝试:
<target name="run">
<exec executable="/bin/bash">
<arg line="/home/myuser/scripts/run.sh"/>
<arg line="-p=8888"/>
<arg line="-z=true"/>
<arg line="/home/myuser/resources/mydir"/>
</exec>
</target>
当我运行它时,除了BUILD SUCCESSFUL 消息外,我没有得到任何 Ant 输出。但是,从终端运行此脚本会产生 loads 的输出。我不确定我是否正确设置了<exec/> 任务,或者如何开始调试它。提前致谢。
更新当我以详细模式运行 ant 时,我得到以下输出:
[exec] Current OS is Linux
[exec] Executing '/bin/bash' with arguments:
[exec] '/home/myuser/scripts/run.sh'
[exec] '-p=8888'
[exec] '-z=true'
[exec] '/home/myuser/resources/mydir'
[exec]
[exec] The ' characters around the executable and arguments are
[exec] not part of the command.
[exec] Usage: <run> [options] <your dir>
所以看起来 Ant 正在我的参数周围插入单引号。有什么方法可以禁用此行为?
【问题讨论】:
-
单引号被插入到日志消息中,因此您可以“看到”空格,它们实际上并未包含在命令运行中(这就是“不是命令的一部分”消息试图表达的意思)。如果你使用 /bin/sh 而不是 /bin/bash 会发生什么?