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 be option of the exit command you will terminate the interpreter as well and see the exit code you supply propagated.
Up vote 2 down vote favorite 1 share g+ share fb share tw.
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 I exit my batch script by: if %errorlevel% neq 0 exit /b %errorlevel% 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 I want to do the following: If the return value is 0 then I have to make the build fail which is not happening now. Any idea how I can get he return value and make the ant build fail? Ant build link|improve this question edited Jul 20 '11 at 8:42martin clayton24.1k43257 asked Jul 20 '11 at 6:47Karthik Krishnan414311 67% accept rate.
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: Or you could set failonerror="true" in the exec task to fail immediately.
OK another thing is, what can I do in ANT Build. Xml with the retun value to make the ANT build report as failure – Karthik Krishnan Jul 20 '11 at 9:01 @Karthik - updated answer with fail ideas. – martin clayton Jul 20 '11 at 9:14 Thanks Martin.
The exit %errorlevel% works now. I am able to get the value in ANT. Works perfectly fine.
I am able to report the build as failure which is what I wanted. Thank you both – Karthik Krishnan Jul 20 '11 at 11:03.
If you run the build script in verbose mode (ant -v), you will notice the line Override ignored for property "BuildErrorCode" Essentially once an ant property has been set its value cannot be changed. This SO question has details. A possible workaround is to not declare the property.
... ...
Thanks Raghuram. Now atleats I get value 0 even though I need to get 2. I will check batch file again.
Thanks – Karthik Krishnan Jul 20 '11 at 7:49.
If you run the build script in verbose mode (ant -v), you will notice the line.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.