Choice (command)

Choice (command)

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. It is available in DOS and Microsoft Windows command line interpreters (shells) such as cmd.exe and COMMAND.COM and was introduced in MS-DOS 6.0. [http://www.computerhope.com/choicehl.htm]

Starting with Windows 2000, the set command has similar functionality using the /P command-line argument.

Usage

The command returns the selected choice using the ERRORLEVEL environment variable 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 ERRORLEVEL value of 255 will be returned. An ERRORLEVEL 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. [ [http://technet.microsoft.com/en-us/library/cc732504.aspx Microsoft TechNet Choice article] ]

yntax

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.

Example

The batch file below gives the user 3 choices. [http://www.computerhope.com/batch.htm] The user is directed depending upon his input by evaluating the ERRORLEVEL environment variable. The selected choice is then printed to the screen using the echo command.

@echo off:BEGINchoice /N /C:123 Please pick a number (1, 2, or 3)%1if ERRORLEVEL =3 goto THREEif ERRORLEVEL =2 goto TWOif ERRORLEVEL =1 goto ONEgoto END:THREEecho You have pressed 3!goto END:TWOecho You have pressed 2!goto END:ONEecho You have pressed 1!:END

ee also

*List of DOS commands

References

External links

* [http://technet.microsoft.com/en-us/library/cc732504.aspx Microsoft TechNet Choice article]


Wikimedia Foundation. 2010.

Игры ⚽ Поможем сделать НИР

Look at other dictionaries:

  • choice (command) — In computing, CHOICE is a DOS command that allows for batch files 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,[1] …   Wikipedia

  • Choice (disambiguation) — Choice consists of the mental process of thinking involved with the process of judging the merits of multiple options and selecting one of them for action. Choice may also refer to: Contents 1 Mathematics 2 Media 3 Other 4 …   Wikipedia

  • Choice — For other uses, see Choice (disambiguation). Choice consists of the mental process of judging the merits of multiple options and selecting one of them. While a choice can be made between imagined options ( what would I do if ...? ), often a… …   Wikipedia

  • Command & Conquer: Renegade — Developer(s) Westwood Studios Publisher(s) EA Games Se …   Wikipedia

  • Command & Conquer: Generals — Command Conquer Generals cover art Developer(s) EA Pacific (Windows) Aspyr Media (Mac OS) …   Wikipedia

  • Command & Conquer: Red Alert (iOS) — Command Conquer: Red Alert Logo of Command Conquer: Red Alert Developer(s) Electronic Arts Pu …   Wikipedia

  • Command.com — Le programme COMMAND.COM est l interpréteur de commandes du système MS DOS. On ne le confondra pas avec cmd.exe, qui est l interpréteur de commande de Windows NT (Windows 2000, Windows XP...) et d OS/2. Les commandes de cmd.exe sont inspirées,… …   Wikipédia en Français

  • Command & Conquer 3: Tiberium Wars — For the related novel, see Command Conquer: Tiberium Wars (novel). CNC3 redirects here. For the Canadian airport with the location identifier, see Brampton Airport. For the television station serving Trinidad and Tobago, see CNC3 Television.… …   Wikipedia

  • Command & Conquer (video game) — This article is about the first Command Conquer video game. For the rest of the series, see Command Conquer. Command Conquer Command and Conquer cover art (Windows 95) Developer(s) Westwood Studios …   Wikipedia

  • Command & Conquer: Red Alert 2 — RA2 redirects here. For Robot Arena 2, see Robot Arena 2: Design and Destroy. Command Conquer: Red Alert 2 On the cover hollywood actor Igor Jijikine Developer(s) Westwood Pacific …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”