{{lowercase}} {{Infobox software | name = choice | logo = | screenshot = ReactOS-0.4.13 choice command 667x434.png | screenshot size = | caption = The ReactOS <code>choice</code> command | developer = Microsoft, Novell, Datalight, Jim Hall, ReactOS Contributors | released = {{Release year|df=yes|1993}} | latest release version = | latest release date = | operating system = DOS, Windows, ReactOS | platform = Cross-platform | genre = Command | license = MS-DOS, PC DOS, DR-DOS, Windows, PTS-DOS: Proprietary commercial software<br />FreeDOS, ReactOS: GPL v2 | website = {{URL|https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/choice}} }} In computing, '''<code>choice</code>''' is a command that allows for batch files to prompt the user to select one item from a set of single-character choices.<ref name="Jamsa1993">{{Citation | last1 = Jamsa | first1 = Kris A. | title = DOS: The Complete Reference | publisher = Osborne McGraw-Hill | page = 206 | year = 1993 | isbn = 0078819040 | url = https://books.google.com/books?id=UW9GAAAAYAAJ | postscript= . }}</ref> It is available in a number of operating system command-line shells.

==History== The command was first introduced as an external command (with filenames CHOICE.COM or CHOICE.EXE) with MS-DOS 6.0.<ref>{{Cite web|url=https://www.computerhope.com/choicehl.htm|title=MS-DOS and Windows command line choice command|website=www.computerhope.com}}</ref> It is included in Novell DOS 7 and IBM PC DOS 7.0, and is also available from the command-line shell of some versions of Microsoft Windows, but not under Windows 2000 and Windows XP.<ref>{{Cite web|url=http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/goto.mspx?mfr=true|title=Microsoft Windows XP Command-line reference A-Z|website=Microsoft}}</ref> It was first made available for Windows in the Windows XP Resource Kit.<ref>{{Cite web|url=https://ss64.com/nt/choice.html|title=Choice - Accept user input - Windows CMD - SS64.com|website=ss64.com}}</ref> It has been reintroduced in Windows Server 2003 and is present in later versions.<ref>{{Cite web|url=https://www.techrepublic.com/blog/windows-and-office/make-the-choice-command-work-for-you-even-in-windows-7/|title=Make the Choice command work for you even in Windows 7|website=TechRepublic|date=13 October 2023 }}</ref>

Starting with Windows 2000, the <code>SET</code> command has similar functionality using the <code>/P</code> command-line argument. However this command requires an additional key stroke (hitting ENTER key), which is not required by <code>choice</code>.

The <code>choice</code> command has been ported to OS/2, Rexx and Perl.<ref>{{Cite web|url=https://www.robvanderwoude.com/choice.php|title=Batch files - The CHOICE command|website=www.robvanderwoude.com}}</ref> It is also available in Datalight ROM-DOS,<ref>{{Cite web|url=https://www.datalight.com/assets/files/ROM-DOS_Users_Guide.pdf|title=Datalight ROM-DOS User's Guide|website=www.datalight.com}}</ref> FreeDOS,<ref>{{Cite web|url=http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/1.2/repos/pkg-html/group-base.html|title=ibiblio.org FreeDOS Group -- FreeDOS Base|website=www.ibiblio.org}}</ref> PTS-DOS,<ref> {{cite web |title=PTS-DOS 2000 Pro User Manual |publisher=Paragon Technology GmbH |location=Buggingen, Germany |date=1999 |url=http://download.paragon-software.com/doc/manual_dos_eng.pdf |access-date=2018-05-12 |url-status=live |archive-url=https://web.archive.org/web/20180512094512/http://download.paragon-software.com/doc/manual_dos_eng.pdf |archive-date=2018-05-12}}</ref> and ReactOS.<ref>{{Cite web|url=https://github.com/reactos/reactos|title=reactos/reactos|website=GitHub|date=27 October 2022 }}</ref> The FreeDOS version was developed by Jim Hall and is licensed under the GPL v2.<ref>{{Cite web|url=http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/1.2/repos/pkg-html/choice.html|title=ibiblio.org FreeDOS Package -- choice (FreeDOS Base)|website=www.ibiblio.org}}</ref>

==Usage== 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 {{keypress|CTRL}}+{{keypress|BREAK}} or {{keypress|CTRL}}+{{keypress|C}}. Choice displays the default choices Y and N if used without parameters.<ref>{{Cite web|url=https://technet.microsoft.com/en-us/library/cc732504.aspx|title=Microsoft TechNet Choice article|date=31 August 2016 }}</ref>

==Syntax==

===DOS=== <code>CHOICE [/C[:]choices] [/N] [/S] [/T[:]c,nn] ["text"]</code>

Arguments: *'''<code>/C[:]choices</code>''' Specifies allowable keys. The default is "YN". *'''<code>/T[:]c,nn</code>''' This defaults choice to "c" after "nn" seconds. *'''<code>text</code>''' Specifies the prompt string to display. (Quotes are optional).

Flags: *'''<code>/N</code>''' Specifies not to display the choices and "?" at end of prompt string. *'''<code>/S</code>''' Specifies that choice keys should be treated as case sensitive.

===Microsoft Windows, ReactOS=== <code>CHOICE [/C [<Choice1><Choice2><…>]] [/N] [/CS] [/T <Timeout> /D <Choice>] [/M <"Text">]</code>

Arguments: *'''<code>/C[:]choices</code>''' 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) *'''<code>/T[:]nn</code>''' This defaults choice to /D after "nn" seconds. Must be specified with default /D. *'''<code>/D[:]c</code>''' This defaults choice to 'c'. *'''<code>/M text</code>''' Specifies the prompt string to display.

Flags: *'''<code>/N</code>''' Specifies not to display the choices and "?" at end of prompt string. *'''<code>/CS</code>''' Specifies that choice keys should be treated as case sensitive.

==Example== The batch file below gives the user three choices.<ref>{{Cite web|url=https://www.computerhope.com/batch.htm|title=Batch File Help and Support|website=www.computerhope.com}}</ref> The user is directed depending upon his input by evaluating the exit code using the <code>IF ERRORLEVEL</code> command (which tests on "greater or equal"). The selected choice is then printed to the screen using the <code>ECHO</code> command.

<syntaxhighlight lang="dosbatch"> @ECHO OFF @CHOICE /C:XYZ IF ERRORLEVEL 3 GOTO Zpressed IF ERRORLEVEL 2 GOTO Ypressed IF ERRORLEVEL 1 GOTO Xpressed GOTO end :Xpressed ECHO You have pressed "X"! GOTO end :Ypressed ECHO You have pressed "Y"! GOTO end :Zpressed ECHO You have pressed "Z"! :end @PAUSE </syntaxhighlight>

:''Note that the example uses the DOS syntax. This example requires slight adjustments before it applies directly to Windows versions of the <code>CHOICE</code> 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== *List of DOS commands *{{Code|select}} in bash

==References== {{Reflist}}

==Further reading== *{{Cite book|author-last=Cooper|author-first=Jim|title=Special Edition Using MS-DOS 6.22, Third Edition|date=2001|publisher=Que Publishing|isbn=978-0789725738}} *{{Cite book|first=William R.|last=Stanek|year=2008|title=Windows Command-Line Administrator's Pocket Consultant, 2nd Edition|publisher=Microsoft Press|isbn=978-0735622623}}

==External links== {{Wikibooks|Guide to Windows Commands}} *[https://technet.microsoft.com/en-us/library/cc732504.aspx Microsoft TechNet Choice article]

{{Windows commands}}

Category:External DOS commands Category:Microcomputer software Category:ReactOS commands Category:Windows administration