title: How do I print the return value of a program in a loop in a batch file script?
body: <p>The task is to run a program(the same program) for ten times and output for each run the exit code(the return value of the main function). So I want to run a batch file(Windows), like this:</p>
  
  <pre><code>FOR /l %%x IN (1,1,10) DO (
      AutomatedTest.exe cip.log
      ECHO %ERRORLEVEL%
  )
  </code></pre>
  
  <p>The code above should do it if you're thinking intuitively, but it doesn't work because the code that it's running is actually:</p>
  
  <pre><code>(
      AutomatedTest.exe cip.log
      ECHO 0
  )
  </code></pre>
  
  <p>and this piece is executed 10 times.</p>
  
  <p>Any ideas on how to make it work?
  Thanks!</p>