ekolis Aug 3, 2019 @ 4:16pm
How do I launch a game from a batch file and wait for it to exit?
I've got this autohost app that processes turns for Space Empires V, but when I run the Steam version of SE5 using the -applaunch command line argument, the batch file exits immediately without waiting for SE5 to close, so the autohost thinks the turn is done processing and uploads the old turn file. How can I make the batch file wait for SE5 to exit before it exits itself?
< >
Showing 1-1 of 1 comments
Straypuft Oct 20, 2021 @ 7:04pm 
Dont know if you ever found a solution after all this time but I may have.

I found something that works for me at least on this page from a google search: https://serverfault.com/questions/245393/how-do-you-wait-for-an-exe-to-complete-in-batch-file

I scrolled down and found a reply by FreeSoftwareServers:

TIMEOUT /T 60 SETLOCAL EnableExtensions set EXE=MYEXETOCHECK.exe :LOOPSTART FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %EXE%"') DO IF %%x == %EXE% goto FOUND goto FIN :FOUND TIMEOUT /T 30 goto LOOPSTART :FIN

pasted it into my batch file and changed the
set EXE=MYEXETOCHECK.exe
to the game exe I needed. I didnt edit any other line from that code and it seems to work, I let it run for a few minutes, tabbing out to see what the bat window was doing, other than several 30 second countdowns like I think it should be working, exited the game and let the countdown do its thing then it did the next thing I wanted the bat to do so I think its a win.
< >
Showing 1-1 of 1 comments
Per page: 1530 50

Date Posted: Aug 3, 2019 @ 4:16pm
Posts: 1