Choice command in Windows
The choice command prompts the user to select an item from the list of single character options in a batch program and then returns the index of that option. If used without parameters, the choice command will show the default options of Y and N.
For an example of how to use this command, please see the Example below.
Syntax of choice
choice [/c [<…>]] [/n] [/cs] [/t /d ] [/m <"Text">]
Parameters
Parameter Description / c Specifies the list of options created. Valid options include az, AZ, 0-9 and extended ASCII characters (128-254). The default list is "YN", displayed as [Y, N] ?. / n Hide the list of options, although the choices are still active and the message content (if specified by parameter / m) is still displayed. / cs Specifies that the options are case sensitive. By default, the options are not case sensitive. / t Specifies the number of seconds to pause before using the default option specified by / d. The accepted value is from 0 to 9999. If the / t parameter is set to 0 , the selection does not pause before returning the default selection. / d Specify the default option to use after waiting for the number of seconds specified by the parameter / t. The default option must be in the list of options specified by the parameter / c. / m <"Text"> Specify a message to display before the list of options. If the parameter / m is not specified, only the prompt will be displayed. /? Show help at the command prompt.Note when using the choice command
The environment variable ERRORLEVEL is set to the index of the key that the user selects from the list of choices. The first option in the list returns a value of 1, the second option returns a value of 2, etc. If the user presses a key that is not a valid choice , choice will issue a warning beep. . If choice detects an error condition, it returns ERRORLEVEL value of 255. If the user presses CTRL + BREAK or CTRL + C , the option returns ERRORLEVEL with 0 .
Note : When you use ERRORLEVEL values in a batch program, list them in descending order.
For example
To display options Y, N and C, enter the following line into a batch file:
choice /c ync
The following prompt appears when the batch file runs the choice command :
[Y,N,C]?
To hide options Y, N and C, but display the text "Yes, No, or Continue", enter the following line into the batch file:
choice /c ync /n /m "Yes, No, or Continue?"
The following prompt appears when the batch file runs the choice command :
Yes, No, or Continue?
Note:
In this example, if the user does not press the key within five seconds, the choice command will select N by default and return an error value of 2. Otherwise, the choice command returns the value corresponding to the user's choice. .
See more:
- Cmdkey command in Windows
- Cmstp command in Windows
- Color command in Windows
- Clip command in Windows
You should read it
- Guide to creating multiple choice questions on VnEdu
- A set of JavaScript multiple-choice questions has P4 answers
- Multiple choice questions about Javascript language
- The app helps you choose a career, choose a school and know the salary
- Switch Case command in JavaScript
- How to create multiple choice questions on VnEdu
- Cmd command in Windows
- Test of PowerPoint computing - Part 3
- Set of multiple choice questions for programming with P8 prizes
- Set of multiple choice questions on programming with P14 prize
- Set of multiple choice questions about programming with P17 prize
- Set of multiple choice questions about programming with P7 prize
Maybe you are interested
How to change the default font in Google Docs - Use the font of choice
6 reasons why Chromebooks should be your next laptop choice
ChatGPT is a better choice than Google Translate when traveling
Forex Trading Made Easier: Best Broker Choices for Filipinos
Compare chips (CPU) AMD and Intel? What is the best choice?
Top choice to buy gaming laptop