Choice
This page is from Microsoft
Updated: January 21, 2005
Syntax
Parameters
Remarks
-
The ERRORVALUE environment variable is set to the index of the key that the user selects from the list of choices. The first key you assign returns a value of 1, the second a value of 2, the third a value of 3, and so on. If the user presses a key that is not among the keys you assigned, Choice.exe sounds a warning beep (that is, it sends a BEL or 07h character to the console). If Choice.exe detects an error condition, it returns an error value of 255. If the user presses CTRL+BREAK or CTRL+C, Choice.exe returns an error value of 0. When you use error value parameters in a batch program, list them in decreasing order.
Examples
choice /c ync
The following appears when you run Choice.exe:
[Y,N,C]?
Type the following syntax in a batch file:
choice /c ync /n /m Yes, No or Continue?
The following appears when you run Choice.exe:
Yes, No, or Continue?
Add text to the syntax as follows:
choice /c ync /mYes, No, or Continue
The following appears when you run Choice.exe:
Yes, No, or Continue [Y,N,C]?
The /t command-line option sets a time limit within which the user must respond and specifies the value to display if the user does not respond within that time limit. To set a time limit of five seconds and specify N as the default value, type the following line in a batch program:
choice /c ync /t 5 /d n
When the batch file starts Choice.exe, the following message appears:
[Y,N,C]?
If the user does not press a key within five seconds, Choice.exe selects N and returns an error value of 2. Otherwise, Choice returns the value corresponding to the user's choice.
Formatting legend
Format | Meaning |
Italic | Information that the user must supply |
Bold | Elements that the user must type exactly as shown |
Ellipsis (...) | Parameter that can be repeated several times in a command line |
Between brackets ([]) | Optional items |
Between braces ({}); choices separated by pipe (|). Example: {even|odd} | Set of choices from which the user must choose only one |
Courier font | Code or program output |