Batch script execution controller
Posted: 27 Jul 2021 15:21
Hi everyone and thanks in advance for the time dedicated
I'm trying to write a batch script that, in sequence:
1) Start an executable (which in this case is "new_emulator.bat", but it is only for example)
2) Controls repeatedly if the process generated from point 1 is still running.
My problem occurs precisely in the control phase, in the only IF present throughout the script (below), because it does not follow the instructions that should perform if the control had successful results, nor what should be performed otherwise ( That is to go back and create another process of the same executable). Please help me, I don't know what to do anymore!
THE SCRIPT:
I'm trying to write a batch script that, in sequence:
1) Start an executable (which in this case is "new_emulator.bat", but it is only for example)
2) Controls repeatedly if the process generated from point 1 is still running.
My problem occurs precisely in the control phase, in the only IF present throughout the script (below), because it does not follow the instructions that should perform if the control had successful results, nor what should be performed otherwise ( That is to go back and create another process of the same executable). Please help me, I don't know what to do anymore!
THE SCRIPT:
Code: Select all
set /A i=0
:infinite_loop
set /A i=%i%+1
set windowTitle=singularBot%i%
START "%windowTitle%" C:\Users\Administrator\Desktop\Nuovo_emulatore.bat
setlocal enableextensions
for /f "tokens=*" %%a in ( 'tasklist /FI "WindowTitle eq %windowTitle%*" /NH' ) do ( set riga=%%a )
set riga=%riga:~0,42%
goto:anomal_closing_check
:anomal_closing_check
for /f "tokens=*" %%a in ( 'tasklist /FI "WindowTitle eq %windowTitle%*" /NH' ) do ( set actual_output=%%a )
set actual_output=%actual_output:~0,42%
timeout /t 4 /nobreak
IF [%riga%] EQU [%actual_output%] (goto stillOpen) ELSE (goto closed)
:stillOpen
timeout /t 4 /nobreak
goto anomal_closing_check
:closed
goto infinite_loop