title: How to store ERRORLEVEL in a variable?
body: <p>I'm trying to store the <code>ERRORLEVEL</code> environment variable into a a local batch variable. But it always turns out to be <code>0</code>.</p>
  
  <pre><code>CALL foo.exe
  SET LEVEL=%ERRORLEVEL%
  IF ERRORLEVEL 1 (
    SET /A ERRORCOUNT=ERRORCOUNT+1
  ) ELSE (
    SET /A OK=OK+1
  )
  ECHO/ &gt;&gt; logtemp.txt
  ECHO ** EXIT %LEVEL% *******************************
  </code></pre>
  
  <p>I have tried to <code>ECHO %ERRORLEVEL%</code> but it always print <code>0</code> too.</p>
  
  <p><code>foo.exe</code> is generating an error and it can be seen by <code>ECHO %ERRORLEVEL%</code> from the command prompt and the <code>ERRORCOUNT</code> is updated correctly.</p>