4

In a cmd window, I want to prompt the user for a set of choices (denoted by letters), one being the default. The user can key in a letter or hit Enter, in which case the default choice will be selected.

I also want to specify a timeout, so the default choice is auto-selected after a given number of seconds of inactivity.

The built-in choice command comes close:

> choice /C YN /T 5 /D Y /M "The message"

This takes only valid choices ( /C YN) and auto-defaults to 'Y' (/D Y) after 5 seconds (/T 5)
... but it strangely does not allow hitting Enter for the default choice.

The other, more verbose option I found permits hitting 'Enter' for the default choice:

:ch
set sel=Y

REM Hitting Enter does not modify 'sel'
set /p sel=The message, [Y/N]?

if %sel% == Y goto Yes
if %sel% == N goto No

echo Invalid choice '%sel%', try again.
goto ch

...but I don't know how to make this one auto-select the default after a while.

1 Answer 1

1

I don't think there's an option, unless you find some 3rd CLI app that can do it.

How about VBS? it'll be way easier to do that...

1
  • I'm not opposed to throwing a vbs script in the %PATH% and using it like a built-in command. But I don't know vbs. Commented Mar 22, 2014 at 20:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .