General discussion


OK a question for all you old DOS users

By JCMiller ·
It's been awhile since I've had to do a DOS batch file, and I seem to remember doing this about O a 100 years ago or so.
is there not a way in a batch file to ask a question (for a Y or N type response).
I should have kept my DOS books here at work......


This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

Use CHOICE command

by csbarnes In reply to OK a question for all you ...

CHOICE gives the [y,n] prompt.

CHOICE [your question]
IF ERROR LEVEL 2 GOTO [END or routine name]
[and so on...]
GOTO [END or routine name]

We use a really simple batch in this format to prompt for a y,n answer here. Hope this helps.

Collapse -


by JCMiller In reply to Use CHOICE command

Csbarnes thanks much

Collapse -


by tbragsda In reply to Use CHOICE command

It supports more than just Y,N You can have it ask any 1 chr response.

@Echo off

Echo Select 1-5 to run some such thing, or A,B,C for somthing realy different.
Echo Choice will default to 1 in 10sec
CHOICE /C:12345abc /N /T:1,10
If ErrorLevel blahblahblah
If ErrorLevel blahblahblah

CHOICE [/C[:]choices] [/N] [/T[:]c,nn] [text]

/C[:]choices Specifies allowable keys. Default is YN
/N Do not display choices and ? at end of prompt string.
/S Treat choice keys as case sensitive.
/T[:]c,nn Default choice to c after nn seconds
text Prompt string to display

ERRORLEVEL is set to offset of key user presses in choices.

Related Discussions

Related Forums