KK99
KK99

Reputation: 1989

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 %ERRORLEVEL% 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%?

Upvotes: 4

Views: 3438

Answers (1)

Jacob
Jacob

Reputation: 43269

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

Upvotes: 4

Related Questions