I am executing ant script in windows. In that consider that, i am executing dir
command in exec
task as below
<target name="dummy">
<exec executable="cmd" failonerror="true">
<arg line="/C DIRR"/>
</exec>
<exec executable="cmd" failonerror="true">
<arg line="/C cd /d c:\temp"/>
</exec>
</target>
Here I have given DIRR
instead of DIR
, this execution will fail. but the ant build is not failing. Its showing the error message as dirr is not recognised as internal or external command
and the next command cd /d c:\temp
also got executed. I want the ant script execution has to be stopped once error message comes.
I want to this script has to stop executing if error occurs in any one of the exec command. failonerror
is also not helping. How to fail the ant build, if exec fails.
Note : I am using ant 1.8.2
Please note, that there are two levels of execution here:
cmd.exe
.cmd.exe
executes DIRSS
.You see, if the the second step fails, this does not necessarily mean, that cmd.exe
does propagate the error back to Ant. This might be more obvious if the mentally replace the well-known cmd.exe
with something "innocent" like foo.exe
.
So the next step is to explore, why the second step behaves differently on your machine than on the machines of the commentators of your question. After that riddle is solved, you can get back to the Ant question.
A first step might be this: Open a new shell window and try
> cmd /c dir
> echo %ERRORLEVEL%
> cmd /c dir nonexisting-directory
> echo %ERRORLEVEL%
> cmd /c dirr
> echo %ERRORLEVEL%
Also tell us the version of your OS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With