Choice (command)

Last updated
choice
Developer(s) Microsoft, Novell, Datalight, Jim Hall, ReactOS Contributors
Initial release1993, 2930 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

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 CTRL+BREAK or CTRL+C. 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:

Flags:

Microsoft Windows, ReactOS

CHOICE [/C [<Choice1><Choice2><…>]] [/N] [/CS] [/T <Timeout> /D <Choice>] [/M <"Text">]

Arguments:

Flags:

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 IFERRORLEVEL3GOTOthreeIFERRORLEVEL2GOTOtwoIFERRORLEVEL1GOTOoneGOTOend:oneECHO You have pressed "1"! GOTOend:twoECHO You have pressed "2"! GOTOend:threeECHO 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

Related Research Articles

<span class="mw-page-title-main">COMMAND.COM</span> Default command line for MS-DOS and Windows 9x

COMMAND.COM is the default command-line interpreter for MS-DOS, Windows 95, Windows 98 and Windows Me. In the case of DOS, it is the default user interface as well. It has an additional role as the usual first program run after boot, hence being responsible for setting up the system by running the AUTOEXEC.BAT configuration file, and being the ancestor of all processes.

dir (command) Directory information command on various operating systems

In computing, dir (directory) is a command in various computer operating systems used for computer file and directory listing. It is one of the basic commands to help navigate the file system. The command is usually implemented as an internal command in the command-line interpreter (shell). On some systems, a more graphical representation of the directory structure can be displayed using the tree command.

at (command) Task scheduling command on various operating systems

In computing, at is a command in Unix-like operating systems, Microsoft Windows, and ReactOS used to schedule commands to be executed once, at a particular time in the future.

An environment variable is a user-definable value that can affect the way running processes will behave on a computer. Environment variables are part of the environment in which a process runs. For example, a running process can query the value of the TEMP environment variable to discover a suitable location to store temporary files, or the HOME or USERPROFILE variable to find the directory structure owned by the user running the process.

cmd.exe Command prompt program

Command Prompt, also known as cmd.exe or cmd, is the default command-line interpreter for the OS/2, eComStation, ArcaOS, Microsoft Windows, and ReactOS operating systems. On Windows CE .NET 4.2, Windows CE 5.0 and Windows Embedded CE 6.0 it is referred to as the Command Processor Shell. Its implementations differ between operating systems, but the behavior and basic set of commands are consistent. cmd.exe is the counterpart of COMMAND.COM in DOS and Windows 9x systems, and analogous to the Unix shells used on Unix-like systems. The initial version of cmd.exe for Windows NT was developed by Therese Stowell. Windows CE 2.11 was the first embedded Windows release to support a console and a Windows CE version of cmd.exe. The ReactOS implementation of cmd.exe is derived from FreeCOM, the FreeDOS command line interpreter.

<span class="mw-page-title-main">XCOPY</span> Computing command

In computing, XCOPY is a command used on IBM PC DOS, MS-DOS, IBM OS/2, Microsoft Windows, FreeDOS, ReactOS, and related operating systems for copying multiple files or entire directory trees from one directory to another and for copying files across a network.

more (command) Terminal pager available on various operating systems

In computing, more is a command to view the contents of a text file one screen at a time. It is available on Unix and Unix-like systems, DOS, Digital Research FlexOS, IBM/Toshiba 4690 OS, IBM OS/2, Microsoft Windows and ReactOS. Programs of this sort are called pagers. more is a very basic pager, originally allowing only forward navigation through a file, though newer implementations do allow for limited backward movement.

In computing, SUBST is a command on the DOS, IBM OS/2, Microsoft Windows and ReactOS operating systems used for substituting paths on physical and logical drives as virtual drives.

<span class="mw-page-title-main">ATTRIB</span>

In computing, ATTRIB is a command in Intel ISIS-II, DOS, IBM OS/2, Microsoft Windows and ReactOS that allows the user to change various characteristics, or "attributes" of a computer file or directory. The command is also available in the EFI shell.

A batch file is a script file in DOS, OS/2 and Microsoft Windows. It consists of a series of commands to be executed by the command-line interpreter, stored in a plain text file. A batch file may contain any command the interpreter accepts interactively and use constructs that enable conditional branching and looping within the batch file, such as IF, FOR, and GOTO labels. The term "batch" is from batch processing, meaning "non-interactive execution", though a batch file might not process a batch of multiple data.

find (Windows)

In computing, find is a command in the command-line interpreters (shells) of a number of operating systems. It is used to search for a specific text string in a file or files. The command sends the specified lines to the standard output device.

In computing, label is a command included with some operating systems. It is used to create, change, or delete a volume label on a logical drive, such as a hard disk partition or a floppy disk. Used without parameters, label changes the current volume label or deletes the existing label.

format (command)

In computing, format, a command-line utility that carries out disk formatting. It is a component of various operating systems, including 86-DOS, MS-DOS, IBM PC DOS and OS/2, Microsoft Windows and ReactOS.

title (command) Command of command line interpreters

In computing, title is a command in various command-line interpreters (shells) on Microsoft Windows and ReactOS that changes the title for the graphical terminal emulator window. The command is also used within DFS and ADFS to change the title of the disc in the current drive.

net (command)

In computing, net is a command in IBM OS/2, Microsoft Windows, ReactOS and Greentea OS used to manage and configure the operating system from the command-line. It is also part of the IBM PC Network Program for DOS.

In computing, ftype is a command-line utility on Microsoft Windows that is used to display or change the link between a file type and an executable program.

In computing, findstr is a command in the command-line interpreters (shells) of Microsoft Windows and ReactOS. It is used to search for a specific text string in computer files.

In computing, diskcomp is a command used for comparing the complete contents of a floppy disk to another one.

replace (command)

In computing, replace is a command that is used to replace one or more existing computer files or add new files to a target directory. Files with a hidden or system attribute set cannot be replaced using replace. The command lists all files that are replaced.

References

  1. Jamsa, Kris A. (1993), DOS: The Complete Reference, Osborne McGraw-Hill, p. 206, ISBN   0078819040.
  2. "MS-DOS and Windows command line choice command". www.computerhope.com.
  3. "Microsoft Windows XP Command-line reference A-Z". Microsoft .
  4. "Choice - Accept user input - Windows CMD - SS64.com". ss64.com.
  5. "Make the Choice command work for you even in Windows 7". TechRepublic. 13 October 2023.
  6. "Batch files - The CHOICE command". www.robvanderwoude.com.
  7. "Datalight ROM-DOS User's Guide" (PDF). www.datalight.com.
  8. "ibiblio.org FreeDOS Group -- FreeDOS Base". www.ibiblio.org.
  9. "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.
  10. "reactos/reactos". GitHub. 27 October 2022.
  11. "ibiblio.org FreeDOS Package -- choice (FreeDOS Base)". www.ibiblio.org.
  12. "Microsoft TechNet Choice article". 31 August 2016.
  13. "Batch File Help and Support". www.computerhope.com.

Further reading