Ant EXEC无法运行bash脚本 [英] Ant EXEC failing to run bash script

查看:96
本文介绍了Ant EXEC无法运行bash脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ant运行bash脚本.

I am trying to use ant to run a bash script.

我发现exec指令是工作的工具

Ive found that the exec directive is the tool for the job

我创建了一个bash脚本test.sh 然后在我的蚂蚁目标中添加:

I created a bash script test.sh and in my ant target i added:

<project basedir=".">
    <property name="temp.deployment.dir" value="temp_deployment_dir"/>
    <property name="temp.dir" value="temp_upload_dir"/>
    <property name="src.dir" value="www"/>
    <property name="js.dir" value="${src.dir}/public/js"/>
    <property name="css.dir" value="${src.dir}/public/css"/>
    <property name="img.dir" value="${src.dir}/public/images/"/>
    <target name="clean">
            <delete dir="${temp.dir}"/>
    </target>
    <target name="update-statics">
            <mkdir dir="${temp.dir}"/>
            <!--TODO: add statics in -->
    </target>
    <target name="deploy">
            <mkdir dir="${$temp.deployment.dir}"/>
            <copy todir="${temp.deployment.dir}">
                    <fileset dir="${src.dir}"/>
            </copy>
            <exec executable="bash" newenvironment="false" dir=".">
                <arg value="cmd_update.sh"/>
            </exec>
     </target>
</project>

我在运行时获得了成功的构建,但是test.sh从未运行.

I get build successful when i run it, but the test.sh is never run.

我已经搜索并搜索了我可能做错的事情,但是因为没有错误,我在调试它时遇到了麻烦.有谁知道exec指令的正确用法,或者我显然做错了什么.据我所知,我正在执行的操作与我所发现的其他exec示例相同.

I have googled and searched for what I could be doing wrong but because there is no error I am having trouble debugging it. Does anyone know the proper usage of the exec directive or if there is something I am clearly doing wrong. From What I can tell I am doing it the same as ever other example of exec I have found.

推荐答案

如果您有 shebang 在您的Bash脚本中,并且您的脚本是可执行的,您不需要包含bash作为命令. (当然,我假设使用Linux,Unix或Mac).

If you have the shebang in your Bash script, and your script is executable, you don't need to include bash as the command. (I am, of course, assuming Linux, Unix, or Mac).

<exec executable="${path.to.command}/cmd_update.sh"
    failonerror="true"
    osfamily="unix"/>

始终将failonerror设置为true,并始终设置osfamily.

Always set failonerror to true and always set osfamily.

也许还需要设置其他内容,例如存储 STDOUT STDERR 的属性.您还可以通过<arg value>子任务传递参数.

There maybe other things you want to set like the property where STDOUT and STDERR are stored. You can also pass parameters via the <arg value> sub-tasks.

我不会使用searchpath参数,因为这可能是一个安全漏洞.

I would not use the searchpath parameter since that could be a security hole.

这篇关于Ant EXEC无法运行bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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