Doscommand line choice command usage details _ dos choice command usage instructions, choice_dos

Source: Internet
Author: User

Doscommand line choice command usage details _ dos choice command usage instructions, choice_dos

Doscommand-line choice command usage details mainly introduce how to use the doscommand-line choice command. For more information, see.

Choice command

You can run different commands by entering a single character. The/c: parameter should be added for use, and c: should be followed by a prompt to enter characters without spaces. The return code is 1234 ....... This command may be unavailable in some Windows versions (such as Windows XP.

Syntax:

CHOICE: [/C [:] key table] [/N] [/S] [/T [:] Select a value, in seconds] [display text]

/C indicates an optional button,/N indicates that no prompt information is displayed,/S indicates that the case-sensitive mode is case-sensitive,/T indicates that if no selection is made within the time limit, select a value defined in Automatic Execution/C. The displayed text is the prompt information when the CHOICE command is executed. The selection result is represented by the ERRORLEVEL value.

Example:

@ Echo off

Choice/c: dimethyl defrag, mem, end

If errorlevel 3 goto defrag

REM should first determine the highest error code

If errorlevel 2 goto mem

If errorlevel 1 goto end

: Defrag

C: \ dos \ defrag

Goto end

: Mem

Mem

Goto end

: End

Echo good bye

After this file is run, defrag, mem, end [D, M, E]? You can select d m e, and then the if statement will make a judgment. d indicates the program segment with the execution label as defrag, and m indicates the program segment with the execution label as mem, e indicates the program segment whose execution label is end. Each program segment finally jumps the program to the end label using goto end. Then, the program displays good bye, and the file ends.

Replaceable commands

You cannot use the CHOICE command on Windows XP. To use similar functions, you can use the SET command. For details, refer to the Set command/P option.

Choice is generally used in cmd batch processing to perform different operations based on user input. It is very useful, for example:

The following two software are executed based on user selection:

@ Echo off

Remote Assistance Tool Set

: Start

Cls

Color 0a

MODE con: COLS = 60 LINES = 20

Echo.

Echo ====================================

Select remote tools for echo

Echo ====================================

Echo.

Echo 1. AnyDesk

Echo.

Echo 2. TeamViewer

Echo.

Echo.

: Cho

Set choice =

Set/p choice = enter the tool Number:

If not "% Choice %" = "" SET Choice = % Choice :~ 0, 1%

If/I "% choice %" = "1" goto AnyDesk

If/I "% choice %" = "2" goto TeamViewer

: AnyDesk

Anyregion .exe

Exit

: TeamViewer

TeamViewer.exe

Exit

The following describes how to use choice commands.

CHOICE [/C choices] [/N] [/CS] [/T timeout/D choice] [/M text]

Description:

This tool allows you to select a project from the selection list and return the index of the selected project.

Parameter List:

/C choices specifies the list of options to be created. The default list is "YN ".

/N hide the Option List at the prompt. The preceding message is displayed, and the option is still enabled.

/CS allows you to select the case sensitivity option. By default, this tool is case-insensitive.

/T timeout specifies the number of seconds before the default value is set. The acceptable value ranges from 0 to 9999. If 0 is specified, no pause is performed. The default option is selected.

/D choice: Specify the default option after nnnn seconds. The characters must be in the selection of a group specified by the/C option, and the/T must be used to specify the nnnn.

/M text specifies the message to be displayed before the prompt. If not specified, only the prompt is displayed.

/? This help message is displayed.

Note:

The ERRORLEVEL environment variable is set to the key index selected from the selected set. Returns 1 for the first choice listed, 2 for the second choice, and so on. If the key you press is not a valid choice, the tool generates a warning. If the tool detects an error, it returns the ERRORLEVEL value of 255. If you press Ctrl + Break or Ctrl + C, the tool returns the ERRORLEVEL value of 0. When the ERRORLEVEL parameter is used in a batch program, the parameters are sorted in descending order.

Example:

CHOICE /?

For CHOICE/c ync/M ", Press Y, N, or C. "

CHOICE/T 10/C ync/CS/D y

Select a for CHOICE/C AB/M "option 1 and B for option 2. "

CHOICE/C AB/N/M "option 1 select a, option 2 select B. "

The following is an introduction from a foreign website.

The CHOICE command was introduced in MS-DOS 6 and is still available in MS-DOS 7 (Windows 95/98 ).

In Windows NT 4, 2000 and XP, CHOICE is no longer a part of the standard distribution. It is, however, available as part of the Windows NT 4 Resouce Kit.

On the other hand, if you still have that old unused MS-DOS 6 or Windows 95/98 version lying around, you can use the CHOICE. COM from that version instead .(*)

Just copy it to a directory that is in your PATH.

Note: 16-bit DOS versions will not work in 64-bit Windows versions.

CHOICE is available again in Windows Vista and later versions.

Most of this means that this command will always exist in later systems, but note that 16-bit systems cannot come with 64-bit systems, the 64-bit system we have installed has integrated 64 choice commands, so you can use them with confidence.

Note

The ERRORVALUE environment variable is set as the index of the key selected by the user from the selection list. The first key you assign will return 1, the second will return 2, the third will return 3, and so on. If the user presses the button in the middle of your designated key, choice.exe will send a warning (that is, it sends a BEL or 07 h character to the console ). If Choice.exe detects an error, it returns an error value of 255. If you press Ctrl + Break or ctrl+c, choice.exe returns the error value 0. When you use error value parameters in the batch processing program, list them in descending order.

Example

Type the following syntax in the batch file:

Choice/c ync

When Choice.exe is run, the following statements are displayed:

[Y, N, C]?

Type the following syntax in the batch file:

Choice/c ync/n/m Yes, No or Continue?

When Choice.exe is run, the following statements are displayed:

Yes, No, or Continue?

Add the text to the syntax as follows:

Choice/c ync/m Yes, No, or Continue

When Choice.exe is run, the following statements are displayed:

Yes, No, or Continue [Y, N, C]?

The/t command line option sets a time limit (within which the user must respond) and specifies the value displayed when the user does not respond within the time limit. To set the time limit to five seconds and specify N as the default value, type the following command line in the batch processing program:

Choice/c ync/t 5/d n

When Choice.exe is started for a batch file, the following message is displayed:

[Y, N, C]?

If the user fails to press a key within five seconds, choice.exe selects N and Returns Error 2. Otherwise, Choice returns the value selected by the user.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.