General discussion

Locked

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


Thanks
JC

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| 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.

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.

Collapse -

Thanks

by JCMiller In reply to Use CHOICE command

Csbarnes thanks much

Collapse -

More

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

Back to Desktop Forum
3 total posts (Page 1 of 1)  

Related Discussions

Related Forums