在Ant中,如何从执行程序中获取返回值? [英] In Ant, how do I get the return value from an exec?

查看:254
本文介绍了在Ant中,如何从执行程序中获取返回值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

在此任务中,可执行文件将返回一个值,该值指示我的应用程序的状态.我如何获得在Ant构建文件中返回的值.我将使用此值来确定某些行为.

In this task, the executable will return a value which will indicate the state of my app. How could I get the value returned in the Ant build file. I will use this value to determine some behaviour.

推荐答案

使用resultproperty和failonerror属性. html"rel =" noreferrer> 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任务文档报价错误和返回代码:

默认情况下,执行程序的返回码 被忽略;当你设置 failonerror ="true",然后返回 代码信令失败(特定于OS) 导致构建失败. 或者,您可以设置 结果名称 属性并将其分配给 结果代码(除非 当然).

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

如果尝试启动程序 失败,并显示与操作系统有关的错误代码, 然后停止构建,除非 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.

这些错误代码是什么意思?出色地, 它们取决于操作系统.在Windows上 盒子,你必须看看 文件;错误代码2表示否" 这样的程序",通常意味着 不在路上.任何时候你看到 任何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中,如何从执行程序中获取返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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