当命令失败蚂蚁的exec任务 [英] ant exec task when command is fail

查看:124
本文介绍了当命令失败蚂蚁的exec任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些code:

<exec executable="src/main/webapp/bin/webdriver.bat" failonerror="true" resultproperty="return.code">
        <arg line="${ccc}/eeee--report-format JSON --report-file  testResultserer/resultere-data/wwwww.json"/>
    </exec> (1)

所以,现在我想exec命令,(1)时会失败。

So, now I would like to exec command , when (1) are going fail.

我怎样才能做到这一点。

How can I do this.

推荐答案

您可以返回code的值设置属性,然后有条件地执行的财产的价值的其他命令:

You can set property with the value of the return code and then execute the other command conditionally on the property's value:

<project>
  <exec executable="${cmd}" resultproperty="ret1"/>
  <condition property="cmd1failed" value="true">
    <not>
      <equals arg1="0" arg2="${ret1}"/>
    </not>
  </condition>
  <exec executable="echo" xmlns:if="ant:if" if:true="${cmd1failed}">
    <arg value="${cmd} failed"/>
  </exec>
  <exec executable="echo" xmlns:unless="ant:unless" unless:true="${cmd1failed}">
    <arg value="${cmd} didn't fail"/>
  </exec>
</project>

例如

$ ant -f exec.xml -Dcmd=/bin/true
Buildfile: /tmp/exec.xml
     [exec] /bin/true didn't fail

BUILD SUCCESSFUL
Total time: 0 seconds
$ ant -f exec.xml -Dcmd=/bin/false
Buildfile: /tmp/exec.xml
     [exec] Result: 1
     [exec] /bin/false failed

BUILD SUCCESSFUL
Total time: 0 seconds

本使用,如果/除非出台属性蚂蚁1.9.1。

This uses the if/unless attributes introduced with Ant 1.9.1.

如果您正在使用Ant的旧版本,你必须使用单独的目标,像

If you are using an older version of Ant, you'll have to use separate targets, something like

<project default="both">
  <target name="cmd1">
    <exec executable="${cmd}" resultproperty="ret1"/>
    <condition property="cmd1failed" value="true">
      <not>
        <equals arg1="0" arg2="${ret1}"/>
      </not>
    </condition>
  </target>
  <target name="cmd1-fail" depends="cmd1" if="cmd1failed">
    <exec executable="echo">
      <arg value="${cmd} failed"/>
    </exec>
  </target>
  <target name="cmd1-pass" depends="cmd1" unless="cmd1failed">
    <exec executable="echo">
      <arg value="${cmd} didn't fail"/>
    </exec>
  </target>
  <target name="both" depends="cmd1-fail,cmd1-pass"/>
</project>

这篇关于当命令失败蚂蚁的exec任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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