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

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

问题描述

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

推荐答案

使用 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 任务文档错误和返回代码:

默认为 exec 的返回码被忽略;当你设置failonerror="true" 然后任何返回代码信号失败(特定于操作系统)导致构建失败.或者,您可以设置resultproperty 的名称财产并将其分配给结果代码(除非不变性,当然).

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 任务都会出现这样的错误,它是通常不是 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天全站免登陆