Choice (command)
Encyclopedia
In computing
,
command
that allows for batch file
s to prompt the user to select one item from a set of single-character choices. It was introduced as an external command (with filenames CHOICE.COM or CHOICE.EXE) with MS-DOS
6.0, Novell DOS 7 and 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
.
Starting with Windows 2000
, the
If a key is pressed that is not a valid choice, the command will sound a warning beep. If an error condition is detected, a 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.
Arguments:
Flags:
<…>]] [/N] [/CS] [/T /D ] [/M <"Text">]
The user is directed depending upon his input by evaluating the exit code using the
Computing
Computing is usually defined as the activity of using and improving computer hardware and software. It is the computer-specific part of information technology...
,
CHOICE
is a DOSDOS
DOS, short for "Disk Operating System", is an acronym for several closely related operating systems that dominated the IBM PC compatible market between 1981 and 1995, or until about 2000 if one includes the partially DOS-based Microsoft Windows versions 95, 98, and Millennium Edition.Related...
command
Command (computing)
In computing, a command is a directive to a computer program acting as an interpreter of some kind, in order to perform a specific task. Most commonly a command is a directive to some kind of command line interface, such as a shell....
that allows for batch file
Batch file
In DOS, OS/2, and Microsoft Windows, batch file is the name given to a type of script file, a text file containing a series of commands to be executed by the command interpreter....
s to prompt the user to select one item from a set of single-character choices. It was introduced as an external command (with filenames CHOICE.COM or CHOICE.EXE) with MS-DOS
MS-DOS
MS-DOS is an operating system for x86-based personal computers. It was the most commonly used member of the DOS family of operating systems, and was the main operating system for IBM PC compatible personal computers during the 1980s to the mid 1990s, until it was gradually superseded by operating...
6.0, Novell DOS 7 and PC DOS 7.0, and is also available from the command line shell of some versions of Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...
, but not under Windows 2000
Windows 2000
Windows 2000 is a line of operating systems produced by Microsoft for use on personal computers, business desktops, laptops, and servers. Windows 2000 was released to manufacturing on 15 December 1999 and launched to retail on 17 February 2000. It is the successor to Windows NT 4.0, and is the...
and Windows XP
Windows XP
Windows XP is an operating system produced by Microsoft for use on personal computers, including home and business desktops, laptops and media centers. First released to computer manufacturers on August 24, 2001, it is the second most popular version of Windows, based on installed user base...
.
Starting with Windows 2000
Windows 2000
Windows 2000 is a line of operating systems produced by Microsoft for use on personal computers, business desktops, laptops, and servers. Windows 2000 was released to manufacturing on 15 December 1999 and launched to retail on 17 February 2000. It is the successor to Windows NT 4.0, and is the...
, the
SET
command has similar functionality using the /P
command-line argument.Usage
The command returns the selected choice as 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, a 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.
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.
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.
Windows
CHOICE [/C [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
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.