From all the stuff I've found googling, this should work, but it doesn't.
I'm sure someone here can show me what I've done wrong.
This is a test to make sure my code works, before I implement the same concepts in production.
infinite_test.bat is just a test batch file that echos a text line, waits 10 sec, then loops to the beginning.
In theory, my code here is supposed to find that it's still running and loop back to keep checking, but in actuality the code just checks once, then goes to :end. I don't understand why errorlevel is being set to 0, when "find" is actually finding the running task window.
Thanks in advance for any help.
Code: Select all
@echo off
start "Infinite test" infinite_test.bat
:loop
timeout /t 10 >nul
tasklist /fi "imagename eq cmd.exe" /v | find /i "Infinite"
if not errorlevel 1 goto end
echo %errorlevel% - waiting for window to close
goto loop
:end
echo %errorlevel% - batch is done