我正在使用 Ant 调用批处理文件exec
任务并将结果设置为resultpropery
。但返回值永远不会到达Ant。下面是我的代码
<property name="BuildErrorCode" value="abc"/>
<exec executable="cmd" resultproperty="BuildErrorCode" failonerror="false"
dir="C:\workspace\build\">
<arg value="/c"/>
<arg value="cmake_cross_compile.bat"/>
</exec>
<echo message="Error Code:=${BuildErrorCode}" />
我通过以下方式退出批处理脚本:
if %errorlevel% neq 0 exit /b %errorlevel%
当脚本运行时,我总是得到abc
作为值而不是批处理文件的返回值。我的批处理文件返回2
现在我必须停止构建
我想做以下事情:
- 如果返回值是 0 那么我必须使构建失败,但现在不会发生。
知道如何获得返回值并使 ant 构建失败吗?
如果您以详细模式运行构建脚本(ant -v
),你会注意到这一行
Override ignored for property "BuildErrorCode"
本质上,一旦设置了 ant 属性,其值就无法更改。这所以问题 https://stackoverflow.com/questions/3492002/override-ignored-for-property有详细信息。
一个可能的解决方法是不declare
该财产。
...
<!--property name="BuildErrorCode" value="abc"/-->
<exec executable = "cmd" resultproperty="BuildErrorCode" failonerror="false" dir="D:\work">
<arg value="/c"/>
<arg value="cmake_cross_compile.bat"/>
</exec>
...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)