Pause command in a batch file is sometimes skipped if it is preceded by a choice command #13646

Open
opened 2026-01-31 03:48:19 +00:00 by claunia · 3 comments
Owner

Originally created by @slangreck on GitHub (Apr 27, 2021).

Windows Terminal version (or Windows build number)

1.8.1032.0

Other Software

No response

Steps to reproduce

Execute this batch file repeatedly in the terminal:

@echo off & setlocal

choice /m "The illusion of choice"

pause

Expected Behavior

After pressing y or n to answer the choice, execution should be paused until another key is pressed

Actual Behavior

Sometimes the pause command is skipped. "Press any key to continue . . ." is printed, but execution of the batch file is immediately continued, which in this case means it ends because EOL is reached.

This gif shows the behavior. Notice how the first run of the batch pauses until the up arrow key is pressed, but on the second run the pause is skipped and the batch file terminates as soon as y is pressed to answer the choice:
SkipPause

Originally created by @slangreck on GitHub (Apr 27, 2021). ### Windows Terminal version (or Windows build number) 1.8.1032.0 ### Other Software _No response_ ### Steps to reproduce Execute this batch file repeatedly in the terminal: ``` bat @echo off & setlocal choice /m "The illusion of choice" pause ``` ### Expected Behavior After pressing y or n to answer the choice, execution should be paused until another key is pressed ### Actual Behavior Sometimes the pause command is skipped. "Press any key to continue . . ." is printed, but execution of the batch file is immediately continued, which in this case means it ends because EOL is reached. This gif shows the behavior. Notice how the first run of the batch pauses until the up arrow key is pressed, but on the second run the pause is skipped and the batch file terminates as soon as y is pressed to answer the choice: ![SkipPause](https://user-images.githubusercontent.com/31589520/116212464-23cab000-a745-11eb-8b26-31667652dbda.gif)
Author
Owner

@skyline75489 commented on GitHub (Apr 27, 2021):

Does this also happen in conhost (cmd.exe)?

@skyline75489 commented on GitHub (Apr 27, 2021): Does this also happen in conhost (cmd.exe)?
Author
Owner

@slangreck commented on GitHub (Apr 27, 2021):

It does, but only when I open cmd.exe, enter the file name and press enter. If I double click the file in explorer.exe it always works as expected

@slangreck commented on GitHub (Apr 27, 2021): It does, but only when I open cmd.exe, enter the file name and press enter. If I double click the file in explorer.exe it always works as expected
Author
Owner

@slangreck commented on GitHub (Mar 29, 2022):

In case anyone else is having this problem, I finally found a workaround:

pause > NUL | set /p =Press any key to continue . . .

For some reason, this causes the pause command to work as intended. Additionally it allows you to customize the message that is printed to the console.

Credit goes to bob vance on stackoverflow.

@slangreck commented on GitHub (Mar 29, 2022): In case anyone else is having this problem, I finally found a workaround: ``` pause > NUL | set /p =Press any key to continue . . . ``` For some reason, this causes the pause command to work as intended. Additionally it allows you to customize the message that is printed to the console. Credit goes to [bob vance on stackoverflow](https://stackoverflow.com/a/32376365/3080038).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#13646