如何从Ant脚本执行exec得到一个返回值 [英] How to get a return value from an exec in ant script

查看:423
本文介绍了如何从Ant脚本执行exec得到一个返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<target name="CheckState">
     <exec executable="${App.path}"/>
</target>

在此任务中,可执行应用程序将返回一个int值,这将表明我的应用程序的状态。我如何能得到在Ant脚本值返回,我将使用这个值来决定一些行为

In this task, the executable app will return an int value which will indicate the state of my app. How could i get the returned in value in ant script, i will use this value to determine some behaviors

在此先感谢

推荐答案

使用 resultproperty failonerror 属性 EXEC 任务,例如:

Use the resultproperty and failonerror attributes of the exec task, e.g.:

<target name="CheckState">
     <exec executable="${App.path}"
           resultproperty="App.state"
           failonerror="false"/>
     <echo message="App state was: ${App.state}" />
</target>

引用的exec 任务文档的错误,并返回codeS 的:

在默认情况下执行exec返回code
  是忽略;当你设置
  failonerror =真,那么任何回报
  code信号故障(OS特定)
  导致构建失败。
  另外,您也可以设置
  resultproperty到的一个的名称
  财产,并将它分配给
  结果code(除非永恒的
  当然)。

By default the return code of an exec is ignored; when you set failonerror="true" then any return code signaling failure (OS specific) causes the build to fail. Alternatively, you can set resultproperty to the name of a property and have it assigned to the result code (barring immutability, of course).

如果试图启动该程序
  失败与操作系统相关的错误code,
  然后暂停构建,除非
  failifexecutionfails设置为false。
  你可以用它来运行程序,如果
  它的存在,但在其他什么也不做。

If the attempt to start the program fails with an OS dependent error code, then halts the build unless failifexecutionfails is set to false. You can use that to run a program if it exists, but otherwise do nothing.

什么是那些错误codeS是什么意思?好,
  他们都与操作系统有关。在Windows
  盒,你必须看
  文件;错误code 2意味着无
  这样的程序,这通常意味着它
  是不是路径上。你看到的任何时候
  从任何Ant任务这样的错误,这是
  通常不是一个Ant的错误,但有些
  你的机器上配置问题。

What do those error codes mean? Well, they are OS dependent. On Windows boxes you have to look at the documentation; error code 2 means 'no such program', which usually means it is not on the path. Any time you see such an error from any Ant task, it is usually not an Ant bug, but some configuration problem on your machine.

这篇关于如何从Ant脚本执行exec得到一个返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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