Developer(s) | Microsoft, Novell, Jim Hall, ReactOS Contributors |
---|---|
Initial release | 1993, 26–27 years ago |
Operating system | DOS, Windows, ReactOS |
Type | Command |
License | MS-DOS, PC DOS, DR-DOS, Windows, PTS-DOS: Proprietarycommercial software FreeDOS, ReactOS: GPL v2 |
If you’re looking for enough space to play a game of beach rounders, Praia Dos Salgados is a great choice. Not only is it super-long and wide, it’s also flat as pancake. Its inland edge is fringed by swampy marshland, but getting to the sand is a doddle thanks to the wide, pushchair-friendly boardwalks.
In computing,
choice
is a command that allows for batch files to prompt the user to select one item from a set of single-character choices.[1]- 3Syntax
History[edit]
The command was introduced as an external command (with filenames CHOICE.COM or CHOICE.EXE) with MS-DOS 6.0,[2]Novell DOS 7 and IBMPC DOS 7.0, and is also available from the command-lineshell of some versions of MicrosoftWindows, but not under Windows 2000 and Windows XP.[3]It has been reintroduced in Windows Server 2003 and is present in later versions.[4]
Starting with Windows 2000, the
SET
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 by choice
.The
choice
command has been ported to OS/2, Rexx and Perl.[5] It is also available in FreeDOS,[6]PTS-DOS,[7] and ReactOS.[8] The FreeDOS version was developed by Jim Hall and is licensed under the GPL v2.[9]Usage[edit]
The command returns the selected choice as an exit 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 presses CTRL+BREAK or CTRL+C.Choice displays the default choices Y and N if used without parameters.[10]
Syntax[edit]
DOS[edit]
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.
Microsoft Windows, ReactOS[edit]
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.
Example[edit]
The batch file below gives the user three choices.[11]The user is directed depending upon his input by evaluating the exit code using the
IF ERRORLEVEL
command (which tests on 'greater or equal'). The selected choice is then printed to the screen using the ECHO
command.- Note that the example uses the DOS syntax. This example requires slight adjustments before it applies directly to Windows versions of the
CHOICE
command. - Note that the IF command, when checking the ERRORLEVEL, compares the number and matches if ERRORLEVEL is equal to or higher than that number. Because of this IF ERRORLEVEL comparisons should be done in decrementing order.
- Note that if the user presses Control-C to escape CHOICE followed by N then the program will continue. The first 'Goto end' is needed.
See also[edit]
References[edit]
- ^Jamsa, Kris A. (1993), DOS: The Complete Reference, Osborne McGraw-Hill, p. 206, ISBN0078819040.
- ^http://www.computerhope.com/choicehl.htm
- ^Microsoft Windows XP Command-line reference A-Z
- ^http://www.techrepublic.com/blog/windows-and-office/make-the-choice-command-work-for-you-even-in-windows-7
- ^http://www.robvanderwoude.com/choice.php
- ^http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/1.2/repos/pkg-html/group-base.html
- ^'PTS-DOS 2000 Pro User Manual'(PDF). Buggingen, Germany: Paragon Technology GmbH. 1999. Archived(PDF) from the original on 2018-05-12. Retrieved 2018-05-12.
- ^https://github.com/reactos/reactos/blob/master/base/shell/cmd/choice.c
- ^http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/1.2/repos/pkg-html/choice.html
- ^Microsoft TechNet Choice article
- ^http://www.computerhope.com/batch.htm
Further reading[edit]
- Cooper, Jim (2001). Special Edition Using MS-DOS 6.22, Third Edition. Que Publishing. ISBN978-0789725738.
- Stanek, William R. (2008). Windows Command-Line Administrator's Pocket Consultant, 2nd Edition. Microsoft Press. ISBN978-0735622623.
External links[edit]
Wikibooks has a book on the topic of: Guide to Windows Commands |
Retrieved from 'https://en.wikipedia.org/w/index.php?title=Choice_(command)&oldid=934429169'