Skip to main content

How to Pause a Script and Wait for User Input with PAUSE

One of the most common issues with simple batch scripts is that when double-clicked, they execute their commands in a flash and the window closes immediately, giving the user no time to read the output. To create a user-friendly script, you need a way to halt execution and wait for the user to acknowledge a message. The simplest, most direct tool for this is the PAUSE command.

This guide will teach you how to use the PAUSE command to halt your script, how to create a custom prompt message, and how to hide the default "Press any key" text.

The Core Command: PAUSE

The PAUSE command does exactly what its name implies: it pauses the execution of the batch script.

When the command processor encounters PAUSE, it does two things:

  1. It prints the standard message: Press any key to continue . . .
  2. It waits indefinitely until the user presses almost any key (e.g., Enter, Spacebar, a letter key).

Once a key is pressed, the script resumes execution on the very next line.

Basic Example: Halting the Script

This is the most common use case: preventing the command window from closing at the end of a script.

@ECHO OFF
ECHO --- System Status Report ---
ECHO.
ECHO Disk space is OK.
ECHO Network connection is active.
ECHO.
ECHO Report complete.

REM Pause the script so the user can read the output.
PAUSE

Example of User Interaction, in which the script will run, display the messages, and then wait for the user.

--- System Status Report ---

Disk space is OK.
Network connection is active.

Report complete.
Press any key to continue . . .

The window will not close until the user presses a key.

How to Create a Custom Prompt Message

The default "Press any key..." message is functional but generic. You cannot change this message with a switch on the PAUSE command itself. The standard way to provide a custom prompt is to use an ECHO command right before PAUSE.

@ECHO OFF
ECHO All files have been processed.
ECHO Please review the summary above.

ECHO.
ECHO Press the Enter key to exit this window.
PAUSE

This gives the user a more specific instruction, though the default PAUSE message will still appear.

Suppressing the Default "Press any key" Message

If you've created your own custom prompt with ECHO, the default "Press any key..." message becomes redundant and messy. You can easily hide it by redirecting the output of the PAUSE command to the NUL device.

Syntax: PAUSE > NUL

Example of script:

@ECHO OFF
ECHO All files have been processed.
ECHO.

ECHO Press the Enter key to exit this window.
PAUSE > NUL

This script provides a much cleaner user experience, showing only your custom prompt.

All files have been processed.

Press the Enter key to exit this window.

The script is now silently waiting for a keypress.

PAUSE vs. Other Input Commands (SET /P, CHOICE)

It's important to choose the right tool for the job. PAUSE is the simplest but least flexible input command.

  • PAUSE: Halts execution. Waits for any key. Returns no information to the script. Its only purpose is to wait for acknowledgement.
  • SET /P: Prompts for a string. Waits for the user to type text and press Enter. It returns the entered string in a variable.
  • CHOICE: Prompts for a specific key. Waits for a single keypress from a predefined list (e.g., Y or N). It returns the user's choice as an ERRORLEVEL.

Use PAUSE only when you need a simple "gate" and don't care which key the user presses.

Common Pitfalls and How to Solve Them

  • Halting Unattended Scripts: The biggest pitfall is using PAUSE in a script that is supposed to be fully automated (e.g., a scheduled task). An unattended script that hits a PAUSE command will wait forever, never completing its job. Solution: Only use PAUSE in scripts that are intended to be run interactively by a user.
  • Getting User Input: Do not try to use PAUSE to get a "Yes/No" answer. The script has no way of knowing which key the user pressed. Solution: For a Yes/No prompt, always use the CHOICE command.

Practical Example: A "Ready to Proceed" Gate

This script uses PAUSE as a manual checkpoint, giving the user a chance to review a plan of action before the script performs a potentially destructive operation.

@ECHO OFF
SET "TARGET_FOLDER=C:\Users\Admin\Downloads"

ECHO --- Cleanup Script ---
ECHO.
ECHO WARNING: This script will permanently delete all .tmp and .log files
ECHO from the following folder:
ECHO "%TARGET_FOLDER%"
ECHO.

ECHO Please review the target folder and press any key to begin the operation.
ECHO To cancel, close this window now.
PAUSE > NUL

ECHO.
ECHO Proceeding with deletion...
DEL "%TARGET_FOLDER%\*.tmp"
DEL "%TARGET_FOLDER%\*.log"
ECHO Cleanup complete.
PAUSE

Conclusion

The PAUSE command is the simplest and most direct way to halt a batch script and wait for user acknowledgement.

Key takeaways for its effective use:

  • Use PAUSE by itself to halt execution with the default message.
  • Use ECHO before PAUSE to provide a custom message or instruction.
  • Use PAUSE > NUL to suppress the default "Press any key..." text, creating a cleaner interface.
  • PAUSE is only for interactive scripts and should never be used in a fully automated process.