Discussion Locked

OK a question for all you old DOS users

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

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

Thanks
JC

3 replies

by csbarnes

CHOICE gives the [y,n] prompt.

Example:
CHOICE [your question]
IF ERROR LEVEL 2 GOTO [END or routine name]
[command...]
[command...]
[command...]
[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.

by tbragsda

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.
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] [/S] [/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.

This discussion is closed to new replies.