Choice (command)

choice

The ReactOS `choice` command

Developer(s)| Microsoft, Novell, Datalight, Jim Hall, ReactOS Contributors
Initial release| 1993, 32-33 years ago
Operating system| DOS, Windows, ReactOS
Platform| Cross-platform
Type| Command
License| MS-DOS, PC DOS, DR-DOS, Windows, PTS-DOS: Proprietary commercial software
FreeDOS, ReactOS: GPL v2
Website| docs.microsoft.com/en-us/windows-server/administration/windows-commands/choice

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] It is available in a number of operating system command-line shells.

## Contents

* 1 History
* 2 Usage
* 3 Syntax
* 3.1 DOS
* 3.2 Microsoft Windows, ReactOS
* 4 Example
* 5 See also
* 6 References
* 7 Further reading
* 8 External links

## History

The command was first introduced as an external command (with filenames CHOICE.COM or CHOICE.EXE) with MS-DOS 6.0.[2] 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.[3] It was first made available for Windows in the Windows XP Resource Kit.[4] It has been reintroduced in Windows Server 2003 and is present in later versions.[5]

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.[6] It is also available in Datalight ROM-DOS,[7] FreeDOS,[8] PTS-DOS,[9] and ReactOS.[10] The FreeDOS version was developed by Jim Hall and is licensed under the GPL v2.[11]

## 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 + or +. Choice displays the default choices Y and N if used without parameters.[12]

## Syntax

### DOS

`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

`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

The batch file below gives the user three choices.[13] 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.

@ECHO off
@CHOICE /C:123
IF ERRORLEVEL 3 GOTO three
IF ERRORLEVEL 2 GOTO two
IF ERRORLEVEL 1 GOTO one
GOTO end
:one
ECHO You have pressed "1"!
GOTO end
:two
ECHO You have pressed "2"!
GOTO end
:three
ECHO You have pressed "3"!
:end
@PAUSE

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

* List of DOS commands
* `select` in bash

## References

1. ↑ Jamsa, Kris A. (1993), DOS: The Complete Reference, Osborne McGraw-Hill, p. 206, ISBN 0078819040, https://books.google.com/books?id=UW9GAAAAYAAJ.
2. ↑ "MS-DOS and Windows command line choice command". https://www.computerhope.com/choicehl.htm.
3. ↑ "Microsoft Windows XP Command-line reference A-Z". http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/goto.mspx?mfr=true.
4. ↑ "Choice - Accept user input - Windows CMD - SS64.com". https://ss64.com/nt/choice.html.
5. ↑ "Make the Choice command work for you even in Windows 7". 13 October 2023. https://www.techrepublic.com/blog/windows-and-office/make-the-choice-command-work-for-you-even-in-windows-7/.
6. ↑ "Batch files - The CHOICE command". https://www.robvanderwoude.com/choice.php.
7. ↑ "Datalight ROM-DOS User's Guide". https://www.datalight.com/assets/files/ROM-DOS_Users_Guide.pdf.
8. ↑ "ibiblio.org FreeDOS Group -- FreeDOS Base". http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/1.2/repos/pkg-html/group-base.html.
9. ↑ "PTS-DOS 2000 Pro User Manual". Buggingen, Germany: Paragon Technology GmbH. 1999. http://download.paragon-software.com/doc/manual_dos_eng.pdf.
10. ↑ "reactos/reactos". 27 October 2022. https://github.com/reactos/reactos.
11. ↑ "ibiblio.org FreeDOS Package -- choice (FreeDOS Base)". http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/1.2/repos/pkg-html/choice.html.
12. ↑ "Microsoft TechNet Choice article". 31 August 2016. https://technet.microsoft.com/en-us/library/cc732504.aspx.
13. ↑ "Batch File Help and Support". https://www.computerhope.com/batch.htm.

## Further reading

* Special Edition Using MS-DOS 6.22, Third Edition. Que Publishing. 2001. ISBN 978-0789725738.
* Stanek, William R. (2008). Windows Command-Line Administrator's Pocket Consultant, 2nd Edition. Microsoft Press. ISBN 978-0735622623.

## External links

* Microsoft TechNet Choice article

* v
* t
* e

Windows command-line programs and shell builtins

* COMMAND.COM
* Command Prompt
* Windows PowerShell
* Recovery Console

File system navigation|

* cd (chdir)
* dir
* popd
* pushd
* tree

File management|

* attrib
* cacls
* cipher
* compact
* copy
* del (erase)
* deltree
* expand
* icacls
* makecab
* mkdir (md)
* mklink
* move
* recover
* ren (rename)
* replace
* rmdir (rd)
* robocopy
* tar
* xcopy

Disk management|

* chkdsk
* convert
* defrag
* diskcomp
* diskcopy
* diskpart
* drvspace
* fdisk
* format
* label
* manage-bde
* subst
* scandisk
* sys
* vol
* vssadmin

Processes|

* at
* exit
* kill
* powercfg
* runas
* sc
* schtasks
* shutdown
* start
* taskkill
* tasklist

Registry|

* assoc
* ftype
* reg
* regini
* regsvr32

User environment|

* date
* mode
* path
* set
* setx
* time
* title
* ver
* whoami

File contents|

* comp
* edit
* edlin
* fc
* find
* findstr
* print
* type

Scripting|

* choice
* clip
* cscript
* doskey
* echo
* for
* forfiles
* goto
* if
* more
* pause
* prompt
* rem
* timeout

Networking|

* arp
* BITSAdmin
* cURL
* getmac
* hostname
* ipconfig
* net
* netsh
* netstat
* nslookup
* PathPing
* ping
* route
* scp
* sftp
* ssh
* ssh-add
* ssh-agent
* ssh-keygen
* ssh-keyscan
* tracert
* winrm
* winrs

Maintenance and care|

* driverquery
* eventcreate
* eventtriggers
* msiexec
* ntbackup
* sfc
* systeminfo
* w32tm
* WBAdmin
* winsat
* wmic

Boot management|

* bcdedit
* bootcfg
* fixboot
* fixmbr

Software development|

* debug
* exe2bin
* QBasic

Miscellaneous|

* cls
* dism
* dpath
* gpupdate
* help
* MSCDEX
* pentnt
* wsl

* List of DOS commands
* Environment variables

0.00

(0 votes)

Original source: https://en.wikipedia.org/wiki/Choice (command). Read more

|

Retrieved from "https://handwiki.org/wiki/index.php?title=Software:Choice_(command)&oldid=723723"
*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template