PAUSE - Pause
Table of Contents
When you run a batch file by double-clicking it, the command prompt window may close the moment the script finishes, so you cannot read the result.
The PAUSE command solves this. It pauses the batch file and waits until the user presses any key.
Basic Usage
PAUSE takes no options.
PAUSE
When executed, it displays the following message and waits for a key press:
After you press a key, processing resumes from the next line. Keys that do not produce a character on their own, such as Shift or Ctrl, do not count as a key press.
Example in a Batch File
@echo off
setlocal
echo Listing files.
echo.
dir /b *.txt
echo.
echo Done.
pause
endlocal
Placing PAUSE at the end of the batch file lets you check the result before the window closes.
Customizing the Message
The message of PAUSE itself cannot be changed. Instead, display your own message with echo and hide the output of PAUSE with >nul.
@echo off
echo Done. Press any key to exit.
pause >nul
pause >nul is handy when you want to show your own message and only wait for a key press.
Common Uses
Stopping Midway for Debugging
Inserting PAUSE in the middle of a batch file lets you check progress step by step.
@echo off
setlocal
echo Step 1: Copying file...
copy "data.txt" "backup\data.txt" >nul 2>&1
echo Done (error code: %ERRORLEVEL%)
pause
echo Step 2: Deleting old files...
del "temp\*.tmp" >nul 2>&1
echo Done (error code: %ERRORLEVEL%)
pause
echo All steps completed.
endlocal
Giving the User a Chance to Cancel
@echo off
echo Warning: all files in the temp folder will be deleted.
echo Press any key to continue, or press Ctrl+C to cancel.
pause >nul
del /q "temp\*.*"
echo Deletion completed.
PAUSE waits indefinitely until a key is pressed, whereas the TIMEOUT command waits for a specified number of seconds (and can be interrupted by a key press). For automated processing, TIMEOUT is more suitable.
PAUSE keeps waiting for a key press. If it runs under Task Scheduler or another unattended environment, the process never ends. Remove PAUSE from batch files that run unattended.
When the Window Closes Immediately
A batch file started by double-clicking closes its window as soon as the last line finishes, so even error messages vanish before you can read them.
- Add
pauseas the last line: you can read the result after both success and failure. - Run it from Command Prompt: type the file name (for example
result_check.cmd) in an already open window, and the output stays on screen. - Start it with
cmd /k: set a shortcut target tocmd /k "C:\scripts\result_check.cmd"and the window stays open after the script ends.
Things to Keep in Mind
- Pressing
Ctrl + Cinterrupts the batch file even while PAUSE is waiting (if asked “Terminate batch job (Y/N)?”, enterY). - If you already run the batch file from an open command prompt, the window does not close after it ends, so a final PAUSE is unnecessary. It is useful when the file is launched by double-clicking.
timeout /t -1also waits for a key press. However, if input is redirected (for exampletimeout /t -1 < file.txt), it fails with the error “Input redirection is not supported”.
Summary
| Purpose | Syntax |
|---|---|
| Basic pause | pause |
| Hide the message | pause >nul |