I have a batch file that is using the exit
command to return an exit code.
This batch file may, in some cases, be invoked interactively from a commandline, or in other cases, may be run as part of an MSBuild project, using the Exec
task.
- If I use
exit %errorlevel%
within my batch file this works well and MSBuild sees the error code, however an interactive user who is running the batch file from a command window will get a rude exit of cmd.exe in this case. - If I use
exit /b %errorlevel%
the interactive scenario does not get a rude exit, but this also means that thecmd
launched by myExec
task also does not exit, and therefore MSBuild does not see the return value.
As a solution to both problems, I am trying to use exit /b
but launch the batch file from my build script like this:
<Exec Command="Batch.cmd params & exit %errorlevel%" />
The idea being that I explicitly take the 'non-terminal' return from exit /b
and manually call exit
to propogate this value outside of cmd.exe
where the Exec
Build Task can see it.
This seems like the perfect solution, however it isn't working. Exec
still doesn't get the correct error value.