title: How to exit a batch program upon error?
body: <p>I've got a batch file that does several things. If one of them fails, I want to exit the whole program. For example:</p>
  
  <pre><code>@echo off
  type foo.txt 2&gt;&gt; error.txt &gt;&gt; success.txt
  mkdir bob
  </code></pre>
  
  <p>If the file foo.txt isn't found then I want the stderr message appended to the error.txt file, else the contents of foo.txt is appended to success.txt. Basically, if the type command returns a stderr then I want the batch file to exit and not create a new directory. How can you tell if an error occurred and decide if you need to continue to the next command or not?</p>