从 Ant 运行 bash 脚本并向其传递多个参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14616447/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 04:24:01  来源:igfitidea点击:

Running a bash script from Ant and passing it multiple arguments

javabashantexec

提问by IAmYourFaja

I'm trying to run the following command from an Ant build file:

我正在尝试从 Ant 构建文件运行以下命令:

sh /home/myuser/scripts/run.sh -p=8888 -z=true /home/myuser/resources/mydir

So far here's my best attempt:

到目前为止,这是我最好的尝试:

<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>

When I run this, I don't get any Ant output, except a BUILD SUCCESSFULmessage. However, running this script from a terminal produces loadsof output. I'm not sure if I've set up the <exec/>task correctly, or how to even begin debugging this. Thanks in advance.

当我运行它时,我没有得到任何 Ant 输出,除了一条BUILD SUCCESSFUL消息。但是,从终端运行此脚本会产生大量输出。我不确定我<exec/>是否正确设置了任务,或者如何开始调试它。提前致谢。

Updatewhen I run ant in verbose mode, I get the following output:

当我在详细模式下运行 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>

So it looks like Ant is inserting single quotes around my arguments. Any way to disable this behavior?

所以看起来 Ant 在我的参数周围插入单引号。有什么办法可以禁用这种行为?

回答by martin clayton

I suggest you try running the task with Ant in verbose mode - for example by passing -von the Ant command line. You should then see how Ant formats the above task in to a command line.

我建议您尝试在详细模式下使用 Ant 运行任务 - 例如通过传递-vAnt 命令行。然后您应该看到 Ant 如何将上述任务格式化为命令行。

I note that the command you quote is for the Bourne shell sh, but in your exec task you are running bash- could that be a reason for the difference?

我注意到您引用的命令是针对 Bourne shell 的sh,但是在您正在运行的 exec 任务中bash- 这可能是造成差异的原因吗?