PAUSE - Pause
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.
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

中小企業経営者のためのRPA入門 RPA導入を成功させる方法

60分でわかる! AIエージェント 超 入門

コマンドラインの黒い画面が怖いんです。

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門
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.
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.
Summary
| Purpose | Syntax |
|---|---|
| Basic pause | pause |
| Hide the message | pause >nul |