开发者

How to get %ERRORLEVEL% from batch file in Ant

I want to know if its possible to get the return value from batch file in Ant build xml.

My batch file returns %ER开发者_高级运维RORLEVEL% value (batch file returns 2 in my case). I want to know if it's possible to capture this and mark as error in Ant. Below is the code snippet I use:

<exec executable = "cmd">
  <arg value="/c"/>     
   <arg value="C:\workspace\Build\cross_Compile.bat"/>
 </exec>

Currently after the batch file call, build is reported as success always. It looks like Ant is not processing the %ERRORLEVEL% or I am not sure. How I can make Ant process the %ERRORLEVEL%?


Use the resultproperty and failonerror. By default, the errocode is ignored.

<property name="Batcherrcode" value="0"/>
<exec executable = "cmd" failonerror="true" resultproperty="Batcherrcode">
  <arg value="/c"/>     
   <arg value="C:\workspace\Build\cross_Compile.bat"/>
 </exec>
<echo message="Error Code:=${Batcherrorcode}" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜