Kae Travis

Wait For a Process in a Batch File

A while ago I needed to wait for a process in a batch file to finish before the script continued.  I did it by using an If statement to create a ‘spoof’ loop, with a delay between each loop iteration of 5 seconds.  This example waits for the ‘Java.exe’ process to end before the script continues:

REM Run your command line here


REM Wait for spawned Java.exe process to end
:LOOP
tasklist /fo csv /fi "IMAGENAME eq Java.exe" 2>NUL | find /I /N "Java.exe">NUL
IF ERRORLEVEL 1 (
  GOTO CONTINUE
) ELSE (
  Timeout /T 5 /Nobreak
  GOTO LOOP
)

:CONTINUE

REM Clean up shortcuts
Wait For a Process in a Batch File
Wait For a Process in a Batch File

Leave a Reply