Home » General Scripting and Coding » Batch Scripts » Wait For Process in a Batch File

Wait For Process in a Batch File

Posted on by

A while ago I needed to wait for a process to end in a batch file, 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 | find /i "Java.exe" >nul 2>&1
IF ERRORLEVEL 1 (
  GOTO CONTINUE
) ELSE (
  Timeout /T 5 /Nobreak
  GOTO LOOP
)

:CONTINUE

REM Clean up shortcuts

 

Comments have now been disabled. If you have a question to ask about this post please ask the community!