Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to return an error from .bat in Visual Studio (2008 SP1) project?
    text
    copied!<p>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:</p> <ul> <li><p><code>exit 1</code><br>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 the <code>exit</code> causes the caller to exit as well.</p></li> <li><p><code>exit /b 1</code><br>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)").</p></li> </ul> <p>I came across a link that provides me with a solution: <a href="http://www.nabble.com/Re:-bjam-and-Windows-p17457249.html" rel="nofollow noreferrer">http://www.nabble.com/Re:-bjam-and-Windows-p17457249.html</a></p> <p>Essentially it says I have to echo an error message before doing the <code>exit /b</code>. For instance,</p> <pre><code>echo MyProj : error : could not copy files. </code></pre> <p>Does anyone know exactly what message format triggers Visual Studio to recognize an error?</p> <p>I've tried tweaking this and some work and some don't. Seems it has to match something like</p> <pre><code>.*\: .*error.*\: </code></pre> <p>Is this documented anywhere?</p> <p>Thanks.</p> <p>This is with Visual Studio 2008 SP1 on Windows XP Pro SP3 (in case <code>cmd.exe</code> has differing behaviour between Windows versions).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload