Reputation: 17
I'm trying to write a program that will open Chrome, wait for a short period of time then close Chrome, and repeat. At first it was working and then it began to only start timeout if I closed Chrome manually. I've tried these two codes each had the same problem. Code 1
cd C:\Program Files (x86)\Google\Chrome\Application\
:loop
chrome.exe https://www.website.com -incognito
timeout /t 200
taskkill /F /IM chrome.exe /T > nul
goto loop
Code 2
cd C:\Program Files (x86)\Google\Chrome\Application\
:loop
chrome.exe https://www.website.com -incognito
TIMEOUT /NOBREAK /T 200>NUL
taskkill /F /IM chrome.exe /T > nul
goto loop
My knowledge with Windows Batch is very limited, and I pieced this together with a lot of internet searches, so the problem is probably very simple and I'm just not experienced enough to see it. Thank you for your time!
Upvotes: 0
Views: 6499
Reputation: 130819
Not sure why, but chrome.exe runs synchronously unless there is already another chrome.exe process running. The first time you ran, you probably already had chrome running, which is why your code worked asynchronously as expected. But then when you TASKKILL all the chrome processes, it becomes synchronous, and no longer works as you want.
This issue has been reported at http://www.dostips.com/forum/viewtopic.php?f=3&t=7242.
In your case, the solution is simple - just use START to restore the asynchronous behavior.
cd C:\Program Files (x86)\Google\Chrome\Application\
:loop
start "" chrome.exe http://www.dostips.com -incognito
timeout /t 200
taskkill /F /IM chrome.exe /T > nul
goto loop
Upvotes: 2