- Choice (command)
In
computing ,choice
is a command that allows forbatch file s to prompt the user to select one item from a set of single-character choices. It is available inDOS andMicrosoft Windows command line interpreter s (shells) such as
andcmd.exe
and was introduced inCOMMAND.COM MS-DOS 6.0. [http://www.computerhope.com/choicehl.htm]Starting with
Windows 2000 , theset
command has similar functionality using the/P
command-line argument .Usage
The command returns the selected choice using the
ERRORLEVEL
environment variable which is set to the index of the key that the user selects from the list of choices. The first choice in the list returns a value of 1, the second a value of 2, and so forth.If a key is pressed that is not a valid choice, the command will sound a warning beep. If an error condition is detected, anERRORLEVEL
value of 255 will be returned. AnERRORLEVEL
value of 0 will be returned, if the user presses keypress|CTRL+keypress|BREAK or keypress|CTRL+keypress|C.Choice displays the default choices Y and N if used without parameters. [ [http://technet.microsoft.com/en-us/library/cc732504.aspx Microsoft TechNet Choice article] ]yntax
choice [/C [:] choices] [/N] [/S] [/T [:] c,nn] [text]
Arguments:
*/C [:] choices
Specifies allowable keys. The default is "YN".
*/T [:] c,nn
This defaults choice to "c" after "nn" seconds.
*text
Specifies the prompt string to display.Flags:
*/N
Specifies not to display the choices and "?" at end of prompt string.
*/S
Specifies that choice keys should be treated as case sensitive.Example
The batch file below gives the user 3 choices. [http://www.computerhope.com/batch.htm] The user is directed depending upon his input by evaluating the
ERRORLEVEL
environment variable. The selected choice is then printed to the screen using theecho
command.ee also
*
List of DOS commands References
External links
* [http://technet.microsoft.com/en-us/library/cc732504.aspx Microsoft TechNet Choice article]
Wikimedia Foundation. 2010.