SETLOCAL ENABLEDELAYEDEXPANSION
set list=A B C D E
FOR %%a IN (%list%) DO (
start %%a.exe > ouput_%%a.txt
echo 120, 30 second loops = 60 min
FOR /L %%i IN (1,1,120) DO (
REM pause for 30 seconds
ping 1.1.1.1 -n 1 -w 30000 > nul
echo find the running executable
tasklist | findstr %%a.exe > nul
REM !ERRORLEVEL!
REM exit the script if no executable is found (i.e it has run successfully)
if !ERRORLEVEL! equ 1 goto success
)
REM kill executable if we haven't exited yet
taskkill /f /im %%a.exe
:success
)
This code doesn't go through the for loops as I expect them to. I tried to do something like this How to break inner loop in nested loop batch script , but to no avail. Any advice?
EDIT
ERRORLEVEL is not 1 when an executable has finished running.
SETLOCAL ENABLEDELAYEDEXPANSION
set list=A B C D E
FOR %%a IN (%LIST%) DO (
start %%a.exe > ouput_%%a.txt
REM 120, 30 second loops = 60 min
call :innerloop %%a
REM kill executable if we haven't exited yet
taskkill /f /im %%a.exe
)
goto :eof
:innerloop
FOR /L %%i IN (1,1,120) DO (
REM pause for 30 seconds
ping 1.1.1.1 -n 1 -w 30000 > nul
REM find the running executable
tasklist | findstr %%a.exe > nul
REM !ERRORLEVEL!
REM exit the script if no executable is found (i.e it has run successfully)
if %ERRORLEVEL% equ 1 goto :next
)
:next
goto :eof