Reputation: 103
I have a script that should start Firefox with an iMacros script, and after that should detect when Firefox crashes, and if it does crash, the batch restarts Firefox again and so on.
But I noticed that Firefox is restarted many times, regardless of if it is crashing or not
I was wondering how I can change this code so it only restarts when Firefox is not responding.
Code:
@echo off
:loop
cls
taskkill /F /IM Firefox.exe
cls
taskkill /F /IM crashreporter.exe
ping 192.0.2.2 -n 1 -w 4000 > nul
set MOZ_NO_REMOTE=1
timeout /t 4 /nobreak
start "" "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" imacros://run/?m=macros.iim
set MOZ_NO_REMOTE=
ping 192.0.2.2 -n 1 -w 1000000 > nul
goto loop
Upvotes: 0
Views: 3123
Reputation: 3451
The START command takes a /WAIT parameter. This means it won't return control back to your batch script as long as firefox is executing. Assuming firefox stops executing when it crashes (which it looks like you are assuming) then just adding the /WAIT parameter will do what you want.
Upvotes: 0
Reputation: 3471
In this case you need to use a check, look for example at this answer. So in your case, you need to use
@echo off
start "" "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" imacros://run/?m=macros.iim
:loop
tasklist /nh /fi "imagename eq firefox.exe" /fi "status eq running` |find /i "firefox.exe" >nul && (
timeout 60 /NOBREAK
) || (
cls
taskkill /F /IM Firefox.exe
cls
taskkill /F /IM crashreporter.exe
timeout 4 /NOBREAK
set MOZ_NO_REMOTE=1
start "" "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" imacros://run/?m=macros.iim
set MOZ_NO_REMOTE=
)
goto loop
using your code. This should check if firefox is not responding, and if this is not the case it waits 60 seconds. If it is not responding it goes to your restart code.
Upvotes: 1