How ant script fails if exec runtime fails

I am running an ant script in windows. In this, note that I execute the dir command in the exec task, as shown below

 <target name="dummy"> <exec executable="cmd" failonerror="true"> <arg line="/C DIRR"/> </exec> <exec executable="cmd" failonerror="true"> <arg line="/C cd /dc:\temp"/> </exec> </target> 

Here I gave DIRR instead of dir , this execution will fail. but the ant construction does not fail. An error message will dirr is not recognised as internal or external command as dirr is not recognised as internal or external command , and the following cd /dc:\temp also been executed. I want ant script execution to be stopped after an error message appears.

I want this script to stop executing if an error occurs in any exec command. failonerror also does not help. Like ant build failure if exec doesn't work.

Note. I am using ant 1.8.2

+6
source share
1 answer

Please note that there are two levels of execution:

  • Ant calls cmd.exe .
  • cmd.exe performs the DIRSS .

You see that if the second step failed, this does not necessarily mean that cmd.exe propagates the error back to Ant. This may be more obvious if you mentally replace the famous cmd.exe with something "innocent", for example foo.exe .

So, the next step is to study why the second step behaves differently on your machine than on the machines of the commentators of your question. Once this puzzle is solved, you can return to the Ant question.

The first step might be: 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.

+2
source

Source: https://habr.com/ru/post/900407/


All Articles