开发者

How to get %ERRORLEVEL% from batch file in Ant

开发者 https://www.devze.com 2023-03-21 02:30 出处:网络
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 i

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

精彩评论

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