I have a batch file that's being run in a Visual Studio custom build step to copy files into an install directory. I want it to error out properly when the copy fails. The problems with the options I have are:
exit 1
This works within the build sequence fine, but sometimes I want to use the batch file from the command line or from within another batch, and in these cases theexit
causes the caller to exit as well.exit /b 1
This works nicely from the command line or from another batch file, but Visual Studio doesn't recognize that the return code wasn't 0 (i.e. it reports the project having "0 error(s)").
I came across a link that provides me with a solution: http://www.nabble.com/Re:-bjam-and-Windows-p17457249.html
Essentially it says I have to echo an error message before doing the exit /b
. For instance,
echo MyProj : error : could not copy files.
Does anyone know exactly what message format triggers Visual Studio to recognize an error?
I've tried tweaking this and some work and some don't. Seems it has to match something like
.*\: .*error.*\:
Is this documented anywhere?
Thanks.
This is with Visual Studio 2008 SP1 on Windows XP Pro SP3 (in case cmd.exe
has differing behaviour between Windows versions).