ant - 在 Ant 中,如何从 exec 获取返回值?

标签 ant

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

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

最佳答案

使用 resultpropertyfailonerror exec 的属性任务,例如:

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

引自 exec任务文档错误和返回代码:

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

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.

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 - 在 Ant 中,如何从 exec 获取返回值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4344139/

相关文章:

android - 无法从 android studio 运行 cocos2dx 示例游戏

ant - JSPC任务报错

java - Maven java maven-antrun-plugin

java - ant getResourceAsStream null 但在 Eclipse 中正常

java - 使用 android 进行 Ant emma 测试 "Could not find file coverage.em to delete."

ant - 如何在 Ant 中反转路径的元素?

ant - 遍历 Ant 目录中的所有文件名

java - 尽管向项目添加了构建器,但项目属性未显示构建路径

apache - 尽管设置了环境变量,Ant 使用的是 JRE 而不是 JDK

java - 从 Eclipse 中的 build.xml 文件导入库