HOWTO · Batch
The PAUSE Keyword in Batch Script
This tutorial explains how PAUSE waits for a key in a Windows batch script, how to display a message before the wait, and how CMD /K keeps the command window open so you can read output.
On this page
A Windows batch file can close its command window as soon as it finishes, which may leave too little time to read the results. Use PAUSE when the script should wait at a specific point for a key press, or start it with CMD /K when you want the command window to remain open after the script ends. These are different behaviors: one pauses execution inside the script, while the other keeps the command session available.
Understanding the PAUSE Command
In Windows CMD, PAUSE displays the standard “Press any key to continue . . .” prompt and waits for a key. After an ordinary key is pressed, the next batch command runs. Ctrl+C or Ctrl+Break can interrupt the batch file and invoke its termination handling instead of simply continuing. For example, a script can print a result, wait while the user reads it, and then print a closing line. The commands are @echo off, echo Report finished., pause, and echo The script continues here.
The command line pause is useful after a step whose output a person needs to inspect. It does not check whether the person agrees with a choice: an ordinary key press continues the script, while Ctrl+C or Ctrl+Break can interrupt it and trigger termination handling. Do not use it as a safety confirmation before deleting files or changing system settings. A script that runs without an interactive user should also avoid PAUSE, because it will wait indefinitely for keyboard input.
The examples here show Windows CMD syntax and were not executed while preparing this article. A batch file run by double-click may close when its commands finish, so an in-script pause can keep that window visible until the key press.
Showing a Custom Message Before PAUSE
PAUSE has a fixed prompt; it does not accept custom prompt text. To give the user context, print a separate message with echo and then suppress the fixed prompt with pause >nul. For example, use echo Review the report above, then press a key to continue. followed by pause >nul.
The echo command supplies the custom wording, while >nul redirects the output of PAUSE so its standard prompt is hidden. This is useful when the message should explain what the user should read or what the next script step will do. Keep the instruction accurate: pressing a key only resumes the batch file; it does not mean the user approved an action.
If the standard prompt is useful, omit >nul and use pause by itself. In either form, place the pause after the information the user needs to see and before the commands that should wait.
Keeping the Command Window Open with CMD /K
Use CMD /K when you want a command window to remain open after a batch file finishes. For example, from the Run dialog or another command launcher, enter cmd /k ""C:\Scripts\report.bat"", replacing the path with the location of your .bat file. CMD’s /K command-string handling consumes the outer quote pair, leaving the batch-file path quoted so a path containing spaces is treated as one command name. CMD /K runs the command and leaves the command interpreter open afterward, so you can inspect output or enter another command.
This option does not add a pause inside the batch file. The script continues through its commands without waiting at a particular line; the command window remains available once the command completes. The example is Windows CMD syntax and was not executed while preparing this article.
Choosing the Right Approach for a Batch Script
Choose PAUSE when a person should read a message or result at a particular point before the next line runs. Print a short explanation before the pause so the wait has a clear purpose. Use pause >nul if your own echo text is sufficient, or plain pause if the standard prompt is helpful. Avoid adding pauses to routine unattended jobs, where no person may be present to press a key.
Choose CMD /K when the main goal is to keep the command window open after the batch file finishes. This is often convenient when launching a script from a command launcher and then inspecting its final output. It does not stop execution for a user response, and it does not turn a key press into confirmation.
Both approaches apply to Windows batch files running under CMD. Neither reports whether an earlier operation succeeded; check the command’s result separately if the script needs to make a decision based on success or failure. Use a deliberate in-script checkpoint for a human-readable step, and use CMD /K to leave the command session open for further inspection or commands.