title: Honoring exit codes from batch files invoked by msbuild
body: <p>I have a batch file that is using the <code>exit</code> command to return an exit code.</p>
  
  <p>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 <code>Exec</code> task.</p>
  
  <ul>
  <li>If I use <code>exit %errorlevel%</code> within my batch file this works well and MSBuild sees the error code, <strong>however</strong> an interactive user who is running the batch file from a command window will get a rude exit of cmd.exe in this case.</li>
  <li>If I use <code>exit /b %errorlevel%</code> the interactive scenario does not get a rude exit, but this also means that the <code>cmd</code> launched by my <code>Exec</code> task also does not exit, and therefore MSBuild does not see the return value.</li>
  </ul>
  
  <p>As a solution to both problems, I am trying to use <code>exit /b</code> but launch the batch file from my build script like this:</p>
  
  <pre><code>&lt;Exec Command="Batch.cmd params &amp;amp; exit %errorlevel%" /&gt;
  </code></pre>
  
  <p>The idea being that I explicitly take the 'non-terminal' return from <code>exit /b</code> and manually call <code>exit</code> to propogate this value outside of <code>cmd.exe</code> where the <code>Exec</code> Build Task can see it.</p>
  
  <p>This seems like the perfect solution, however it isn't working. <code>Exec</code> still doesn't get the correct error value.</p>