In
computing
Computing is any goal-oriented activity requiring, benefiting from, or creating computing machinery. It includes the study and experimentation of algorithmic processes, and development of both hardware and software. Computing has scientific, e ...
,
choice
is a
command
Command may refer to:
Computing
* Command (computing), a statement in a computer language
* COMMAND.COM, the default operating system shell and command-line interpreter for DOS
* Command key, a modifier key on Apple Macintosh computer keyboards
* ...
that allows for
batch file
Batch may refer to:
Food and drink
* Batch (alcohol), an alcoholic fruit beverage
* Batch loaf, a type of bread popular in Ireland
* A dialect term for a bread roll used in North Warwickshire, Nuneaton and Coventry, as well as on the Wirral ...
s to prompt the user to select one item from a set of single-character choices.
It is available in a number of
operating system
An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs.
Time-sharing operating systems schedule tasks for efficient use of the system and may also in ...
command-line shells.
History
The command was first introduced as an external command (with filenames CHOICE.COM or CHOICE.EXE) with
MS-DOS
MS-DOS ( ; acronym for Microsoft Disk Operating System, also known as Microsoft DOS) is an operating system for x86-based personal computers mostly developed by Microsoft. Collectively, MS-DOS, its rebranding as IBM PC DOS, and a few ope ...
6.0. It is included in
Novell DOS
DR-DOS (written as DR DOS, without a hyphen, in versions up to and including 6.0) is a disk operating system for IBM PC compatibles. Upon its introduction in 1988, it was the first DOS attempting to be compatible with IBM PC DOS and MS-D ...
7 and
IBM PC DOS
PC or pc may refer to:
Arts and entertainment
* Player character or playable character, a fictional character controlled by a human player, usually in role-playing games or computer games
* ''Port Charles'', an American daytime TV soap opera
* ...
7.0, and is also available from the
command-line
A command-line interpreter or command-line processor uses a command-line interface (CLI) to receive commands from a user in the form of lines of text. This provides a means of setting parameters for the environment, invoking executables and pro ...
shell
Shell may refer to:
Architecture and design
* Shell (structure), a thin structure
** Concrete shell, a thin shell of concrete, usually with no interior columns or exterior buttresses
** Thin-shell structure
Science Biology
* Seashell, a hard ou ...
of some versions of
Microsoft
Microsoft Corporation is an American multinational technology corporation producing computer software, consumer electronics, personal computers, and related services headquartered at the Microsoft Redmond campus located in Redmond, Washing ...
Windows
Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for serv ...
, but not under
Windows 2000
Windows 2000 is a major release of the Windows NT operating system developed by Microsoft and oriented towards businesses. It was the direct successor to Windows NT 4.0, and was Software release life cycle#Release to manufacturing (RTM), releas ...
and
Windows XP
Windows XP is a major release of Microsoft's Windows NT operating system. It was released to manufacturing on August 24, 2001, and later to retail on October 25, 2001. It is a direct upgrade to its predecessors, Windows 2000 for high-end and ...
. It was first made available for Windows in the Windows XP
Resource Kit Resource Kit is a term used by Microsoft for a set of software resources and documentation released for their software products, but which is not part of that product. Resource kits offer supplementary resources such as technical guidance, compatibi ...
.
It has been reintroduced in
Windows Server 2003
Windows Server 2003 is the sixth version of Windows Server operating system produced by Microsoft. It is part of the Windows NT family of operating systems and was released to manufacturing on March 28, 2003 and generally available on April 24, 2 ...
and is present in later versions.
Starting with Windows 2000, the
SET
Set, The Set, SET or SETS may refer to:
Science, technology, and mathematics Mathematics
*Set (mathematics), a collection of elements
*Category of sets, the category whose objects and morphisms are sets and total functions, respectively
Electro ...
command has similar functionality using the
/P
command-line argument
A command-line interpreter or command-line processor uses a command-line interface (CLI) to receive commands from a user in the form of lines of text. This provides a means of setting parameters for the environment, invoking executables and pro ...
. 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
OS/2 (Operating System/2) is a series of computer operating systems, initially created by Microsoft and IBM under the leadership of IBM software designer Ed Iacobucci. As a result of a feud between the two companies over how to position OS/2 ...
,
Rexx
Rexx (Restructured Extended Executor) is a programming language that can be interpreted or compiled. It was developed at IBM by Mike Cowlishaw. It is a structured, high-level programming language designed for ease of learning and reading. ...
and
Perl
Perl is a family of two high-level, general-purpose, interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it also referred to its redesigned "sister language", Perl 6, before the latter's name was offici ...
. It is also available in
Datalight
Datalight was a privately held software company specializing in power failsafe and high performance software for preserving data integrity in embedded systems. The company was founded in 1983 by Roy Sherrill, and is headquartered in Bothell, Washi ...
ROM-DOS
Datalight was a privately held software company specializing in power failsafe and high performance software for preserving data integrity in embedded systems. The company was founded in 1983 by Roy Sherrill, and is headquartered in Bothell, Washi ...
,
FreeDOS
FreeDOS (formerly Free-DOS and PD-DOS) is a free software operating system for IBM PC compatible computers. It intends to provide a complete MS-DOS-compatible environment for running Legacy system, legacy software and supporting embedded system ...
,
PTS-DOS
PTS-DOS (aka PTS/DOS) is a disk operating system, a DOS clone, developed in Russia by PhysTechSoft and Paragon Technology Systems.
History and versions
PhysTechSoft was formed in 1991 in Moscow, Russia by graduates and members of MIPT, infor ...
, and
ReactOS
ReactOS is a free and open-source operating system for amd64/i686 personal computers intended to be binary-compatible with computer programs and device drivers made for Windows Server 2003 and later versions of Windows. ReactOS has been noted a ...
. The FreeDOS version was developed by
Jim Hall and is licensed under the
GPL v2
The GNU General Public License (GNU GPL or simply GPL) is a series of widely used free software licenses that guarantee end users the four freedoms to run, study, share, and modify the software. The license was the first copyleft for general us ...
.
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.
Syntax
DOS
CHOICE C[:hoices.html"_;"title=".html"_;"title="C[:">C[:hoices">.html"_;"title="C[:">C[:hoices[/N.html" ;"title="">C[:hoices.html" ;"title=".html" ;"title="C[:">C[:hoices">.html" ;"title="C[:">C[:hoices[/N">">C[:hoices.html" ;"title=".html" ;"title="C[:">C[:hoices">.html" ;"title="C[:">C[:hoices[/N[/S] [/T ,nn] ["text"]
Arguments:
*
/C hoices
Specifies allowable keys. The default is "YN".
*
/T ,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_[<…>_[/N.html" ;"title="Choice1><…>.html" ;"title="C [<…>">C [<…> [/N">Choice1><…>.html" ;"title="C [<…>">C [<…> [/N[/CS] [/T /D ] [/M <"Text">]
Arguments:
*
/C hoices
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 n
This defaults choice to /D after "nn" seconds. Must be specified with default /D.
*
/D
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.
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
In audio signal processing and acoustics, an echo is a reflection of sound that arrives at the listener with a delay after the direct sound. The delay is directly proportional to the distance of the reflecting surface from the source and the list ...
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
This article presents a list of commands used by DOS operating systems, especially as used on x86-based IBM PC compatibles (PCs). Other DOS operating systems are not part of the scope of this list.
In DOS, many standard system commands were pro ...
* in
bash
Bash or BASH may refer to:
Arts and entertainment
* ''Bash!'' (Rockapella album), 1992
* ''Bash!'' (Dave Bailey album), 1961
* '' Bash: Latter-Day Plays'', a dramatic triptych
* ''BASH!'' (role-playing game), a 2005 superhero game
* "Bash" ('' ...
References
Further reading
*
*
External links
Microsoft TechNet Choice article
{{Windows commands
External DOS commands
Microcomputer software
ReactOS commands
Windows administration