![]() TheReactOS choice command | |
Developer(s) | Microsoft,Novell,Datalight,Jim Hall, ReactOS Contributors |
---|---|
Initial release | 1993, 31–32 years ago |
Operating system | DOS,Windows,ReactOS |
Platform | Cross-platform |
Type | Command |
License | MS-DOS, PC DOS, DR-DOS, Windows, PTS-DOS:Proprietarycommercial software FreeDOS, ReactOS:GPL v2 |
Website | docs |
Incomputing,choice
is acommand that allows forbatch files to prompt the user to select one item from a set of single-character choices.[1] It is available in a number ofoperating systemcommand-line shells.
The command was first introduced as an external command (with filenames CHOICE.COM or CHOICE.EXE) withMS-DOS 6.0.[2] It is included inNovell DOS 7 andIBMPC DOS 7.0, and is also available from thecommand-lineshell of some versions ofMicrosoftWindows, but not underWindows 2000 andWindows XP.[3] It was first made available for Windows in the Windows XPResource Kit.[4]It has been reintroduced inWindows Server 2003 and is present in later versions.[5]
Starting with Windows 2000, theSET
command has similar functionality using the/P
command-line argument. However this command requires an additional key stroke (hitting ENTER key), which is not required bychoice
.
Thechoice
command has been ported toOS/2,Rexx andPerl.[6] It is also available inDatalightROM-DOS,[7]FreeDOS,[8]PTS-DOS,[9] andReactOS.[10] The FreeDOS version was developed byJim Hall and is licensed under theGPL v2.[11]
The command returns the selected choice as anexit code 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, an exit code value of 255 will be returned. An exit code value of 0 will be returned if the user pressesCTRL+BREAK orCTRL+C.Choice displays the default choices Y and N if used without parameters.[12]
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. (Quotes are optional).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.CHOICE [/C [<Choice1><Choice2><…>]] [/N] [/CS] [/T <Timeout> /D <Choice>] [/M <"Text">]
Arguments:
/C[:]choices
Specifies allowable keys. The default is "YN". (Microsoft Windows restricts valid choice keys to a-z, A-Z, 0-9 and ASCII values of 128 to 254)/T[:]nn
This defaults choice to /D after "nn" seconds. Must be specified with default /D./D[:]c
This defaults choice to 'c'./M text
Specifies the prompt string to display.Flags:
/N
Specifies not to display the choices and "?" at end of prompt string./CS
Specifies that choice keys should be treated as case sensitive.The batch file below gives the user three choices.[13]The user is directed depending upon his input by evaluating the exit code using theIF ERRORLEVEL
command (which tests on "greater or equal"). The selected choice is then printed to the screen using theECHO
command.
@ECHO off@CHOICE /C:123IFERRORLEVEL3GOTOthreeIFERRORLEVEL2GOTOtwoIFERRORLEVEL1GOTOoneGOTOend:oneECHO You have pressed"1"!GOTOend:twoECHO You have pressed"2"!GOTOend:threeECHO You have pressed"3"!:end@PAUSE
CHOICE
command.select
inbash