windows - How do I print the return value of a program in a loop in a batch file script? -


the task run program(the same program) ten times , output each run exit code(the return value of main function). want run batch file(windows), this:

for /l %%x in (1,1,10) (     automatedtest.exe cip.log     echo %errorlevel% ) 

the code above should if you're thinking intuitively, doesn't work because code it's running actually:

(     automatedtest.exe cip.log     echo 0 ) 

and piece executed 10 times.

any ideas on how make work? thanks!

what need delayed variable expansion:

for /l %%x in (1,1,10) (     automatedtest.exe cip.log     echo !errorlevel! ) 

to enable delayed variable expansion precede batch setlocal enabledelayedexpansion or start command shell cmd.exe /v:on.

another approach using subroutines:

for /l %%x in (1,1,10) call :test goto :eof  :test automatedtest.exe cip.log echo %errorlevel% goto :eof 

yet approach use if errorlevel.


Comments

Popular posts from this blog

c++ - Linked List error when inserting for the last time -

java - activate/deactivate sonar maven plugin by profile? -

tsql - Pivot with Temp Table (definition for column must include data type) -- SQL Server 2008 -