蚂蚁EXEC resultproperty不工作 [英] Ant exec resultproperty is not working

查看:176
本文介绍了蚂蚁EXEC resultproperty不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打电话使用Ant EXEC 任务批处理文件和设置结果 resultpropery 。但返回值没有出现,蚂蚁。下面是我的code

I am calling a batch file using an Ant exec task and setting the result in resultpropery. But the return value never comes to Ant. Below is my code

<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}" />

我通过我的退出批处理脚本:

I exit my batch script by:

if %errorlevel% neq 0 exit /b %errorlevel%

当脚本运行时,我总是得到 ABC 作为值,而不是从批处理文件返回值。我的批处理文件返回 2 现在,我必须停止构建

When the script runs, i always get abc as value instead of return value from batch file. My batch file returns 2 for now and I have to stop the build

我要做到以下几点:


  1. 如果返回值是';> 0,那么我必须使构建失败,这不是现在发生的事情

任何想法我如何能得到他的返回值,使Ant构建失败?

Any idea how I can get he return value and make the ant build fail?

推荐答案

EXEC 任务 resultproperty 将捕获在CMD间preTER退出code。你虽然调用批处理文件的退出方式不是终止CMD,它只是退出脚本。从CMD退出code将不受影响,并保持为零。如果你只是删除exit命令的 \\ b 选项,则终止间preTER也看到出口code你提供传播。

The exec task resultproperty will capture the exit code of the cmd interpreter. The way you are calling exit in the batch file though is not terminating cmd, it is only exiting the script. The exit code from cmd will be unaffected, and stay zero. If you simply remove the \b option of the exit command you will terminate the interpreter as well and see the exit code you supply propagated.

if %errorlevel% neq 0 exit %errorlevel%

要失败,您可以使用 失败任务,也许是这样的:

To fail, you could use a fail task, perhaps something like this:

<fail message="cmake_cross_compile.bat exited non-zero">
    <condition>
       <not>
         <equals arg1="${BuildErrorCode}" arg2="0"/>
       </not>
     </condition>
</fail>

或者你可以设置 failonerror =真正的 EXEC 任务立即失效。

这篇关于蚂蚁EXEC resultproperty不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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