Suppose I have a bat file named parent.bat which looks like
@ECHO off
rem this is parent.bat file
:label
if exist child1.bat (
tasklist /v /fi "IMAGENAME eq cmd.exe"|find /I /c "hello1"
if %ERRORLEVEL% == "0" start child1.exe
)
if exist child2.bat (
tasklist /v /fi "IMAGENAME eq cmd.exe"|find /I /c "hello2"
if %ERRORLEVEL% == "0" start child2.exe
)
if exist child3.bat (
tasklist /v /fi "IMAGENAME eq cmd.exe"|find /I /c "hello3"
if %ERRORLEVEL% == "0" start child3.exe
)
timeout /t 120
goto label
I have child1.bat as
@ECHO off
title hello1
start www.google.com
timeout /t -1
I have child2.bat as
@ECHO off
title hello2
start www.yahoo.com
timeout /t -1
I have child3.bat as
@ECHO off
title hello3
start www.facebook.com
timeout /t -1
My intention is to run facebook,google,yahoo if the child.bat files exist and they are not running
but what happens is even if the child.bat files are running (they are in paused mode) the parent.bat file opens all the child.bat files
Even more some times when i change the qoutes in %ERRORLEVEL% == "0" it does not start child1.bat and child2.bat
sometimes the opposite and sometimes child2.bat and child3.bat are started
:label
for %%f in (1 2 3) do if exist "child%%f.bat" (
tasklist /v /fi "IMAGENAME eq cmd.exe"|findstr /I "hello%%f" >nul
if errorlevel 1 start "child%%f.bat"
)
timeout /t 120
goto :label