HOWTO · Batch

Wait for a Command or Program to Finish in a Windows Batch File

Run commands in order in a Windows batch file: call another batch file with CALL, wait for a STARTed program with START "" /WAIT, and use TIMEOUT only for a delay.

On this page

Commands and executables run directly in a batch file finish before cmd.exe reads the next line. Choose a special command only when calling another batch file or deliberately launching a program with START.

Situation Use this
An ordinary command or executable Run it directly; the next line runs after it returns.
Another .bat or .cmd file call child.cmd so control returns to the parent after the child ends.
A program launched with START start "" /wait program.exe to wait for the process started by START.
A fixed delay or user confirmation timeout or pause; neither detects process completion.

This article shows each case and how to preserve a command’s exit code before another command can replace it.

Run an Ordinary Command or Executable Directly

When a command or executable is on its own line, do not add START just to make the script wait. The next command runs after the first returns. This small batch file illustrates the sequence using built-in echo commands:

@echo off
echo [1] command start
echo [2] command returned
[1] command start
[2] command returned

The same sequencing applies to an executable invoked directly. If later steps need its exit code, save %ERRORLEVEL% immediately after that command; a later command can change it. Use exit /b %rc% to return a previously saved result from a batch file.

Call Another Batch File and Return to the Parent

Calling a batch file by name transfers control to it. Use CALL when the parent must continue afterward. For example, the parent can save the child’s return code immediately:

parent.cmd:

@echo off
echo [parent] before call
call child.cmd input.txt
set "rc=%ERRORLEVEL%"
echo [parent] after call: exit code=%rc%
exit /b %rc%

child.cmd:

@echo off
echo [child] start
echo Processing "%~1"
exit /b

These are separate file illustrations, not an executed fixture. In Windows batch, CALL returns control to the parent after the child ends, and the parent can read the child’s resulting %ERRORLEVEL%. Without CALL, invoking another .bat or .cmd transfers execution to that file and the later parent lines do not run. Pass arguments after the child filename; quote an argument containing spaces. Microsoft documents the command forms and return behavior in its call reference.

Wait for a Program Launched With START

Use START when you intentionally launch a separate program. Add /WAIT to wait for the process that START launches:

start "" /wait "C:\Tools\My Program\worker.exe" --task import
set "rc=%ERRORLEVEL%"
echo worker exit code: %rc%
exit /b %rc%

This Windows-specific command is a syntax illustration; its external executable is not included here, so no execution result is claimed. The empty "" is the window title. It must precede a quoted executable path because START treats its first quoted argument as the title. /B is optional and keeps a console program in the current Command Prompt window; it does not make the command wait. /WAIT is the option for waiting and returning after the launched process ends.

START /WAIT waits for the process it starts. It cannot guarantee that a launcher which starts a separate, detached child process has finished all its own work. Check the launched program’s documentation when that distinction matters. See Microsoft’s start reference for the complete option list and How to Use the START Command in a Batch File for other launch patterns.

Use TIMEOUT or PAUSE Only to Pause the Script

Use TIMEOUT when you deliberately need an elapsed delay, not as proof that another process completed. Microsoft documents /NOBREAK for a countdown that ordinary key presses cannot skip, and TIMEOUT /T -1 as a key-press wait; PAUSE is another interactive prompt. The Windows TIMEOUT command accepts values from -1 through 99999 seconds. A delay may be too short or unnecessarily long, so use CALL or START "" /WAIT when process completion is the condition you need.

For options and examples dedicated to timed delays, see How to Use TIMEOUT in a Batch File.

Troubleshooting

  • Do not use a process-name polling loop as a general replacement for START /WAIT. Multiple processes can share a name, and a launcher can return before a detached child finishes.
  • Read %ERRORLEVEL% immediately after the command you care about. echo, set, and later commands can change it.
  • Do not add cmd /k to automation examples: it deliberately leaves a Command Prompt open instead of reporting whether the script completed.
  • If a program needs administrator rights, user input, network access, or an application-specific completion signal, its own documentation determines whether command-process waiting is sufficient.

Summary

Run ordinary commands directly. Use CALL for another batch file that must return to its caller, and use START "" /WAIT only when you launch a program through START. TIMEOUT and PAUSE pause the batch file but do not tell you whether a program has completed.