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

查看:24
本文介绍了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.

您可能还想设置其他内容,例如存储 STDOUTSTDERR 的属性.您还可以通过 子任务传递参数.

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天全站免登陆