in a code block you need always delayed expansion
:
@echo OFF &SETLOCAL ENABLEDELAYEDEXPANSION
start calc.exe
REM loop 600 times, each loop being 3 seconds (30 minutes total)
FOR /L %%A IN (1,1,600) DO (
REM find the running executable
tasklist | find /I /C "calc.exe" > nul
echo !ERRORLEVEL!
Rem exit the script if no executable is found (i.e it has run successfully)
if !ERRORLEVEL! eq 1 EXIT
Rem pause for 3 seconds
ping 1.1.1.1 -n 1 -w 3000 > nul
)
REM kill executable if we haven't exited yet
taskkill /f /im calc.exe