Are you really good at programming batch files, just don’t know how to make a menu with a choice of yes, no or choice 1, 2 or 3? You have come to the right place!
- 1 Click Start> Run
- 2 Enter "cmd" (without quotes)
- 3 Enter "edit"
- 4 Enter the following commands. After each press enter. All that is in parentheses is NOT required, these are notes with explanations.
- 5 @echo off (This command "hides" the ability to enter commands - optional, but we recommend using it)
- 6 cls (Hides everything above is optional, but if you want everything to look orderly, we recommend it)
- 7: start
- 8 echo.
- 9 echo Choice 1 ("Choice 1" can be renamed as you need)
- 10 echo Choice 2
- 11 echo Choice 3 (Insert as many choices as you need).
- 12 Enter "set / p choice = (Here, insert a question or command, for example," Yes or no?")
- 13 if not "% choice%" == set choice =% choice:
AT Bash there are several commands that can allow you to create a script in which you can describe several actions and provide the user with the number of the desired position and then certain commands are executed, if the user has not selected anything, the default number is substituted and the commands corresponding to this number are executed.
How can this be done at the Windows command prompt.
Please provide examples or articles with a detailed analysis of the features of such teams in BATCH (without using any other languages or installing utilities)
Very kind Developer
CHOICE [/ C list] [/ N] [/ CS] [/ T timeout / D element] [/ M text]
This program allows you to select an item from a list of items
and returns the index of the selected item.
/ C list Creates a list of selectable items.
The default list is "YN".
/ N Hide the list of items in the prompt.
A message is displayed before the invitation
and the items remain available for selection.
/ CS Enables case sensitivity when selecting items.
By default, the program is not case sensitive.
/ T timeout The number of seconds before selecting the default item.
Valid values are from 0 to 9999.
If 0 is specified, there is no pause before selection
item by default.
/ D element The element selected by default in nnnn seconds.
The symbol must be present in the element set.
in / C, nnnn is specified in / T.
/ M text Message displayed before
an invitation. If not specified, the program
/? Display help for use.
ERRORLEVEL environment variable gets index value
the key corresponding to the selected item. First element
in the list returns 1, the second - 2, etc.
If the user presses a key that is not appropriate
selectable, a beep sounds. If an error is detected,
returns ERRORLEVEL 255. If keys are pressed
CTRL + BREAK or CTRL + C, the program returns an ERRORLEVEL value of 0.
When using the ERRORLEVEL parameters in a batch program, their
should be listed in descending order.
CHOICE / C YNC / M "Y - Yes, N - No, C - Cancel."
CHOICE / T 10 / C ync / CS / D y
CHOICE / C ab / M “a” to select parameter 1 and “b” to select parameter 2.
CHOICE / C ab / N / M “a” to select parameter 1 and “b” to select parameter 2.
After 5 seconds, Y will be automatically selected.
The serial number of the selected letter will be saved as an error return code.
Note that capitalization (if / CS is not specified) is ignored in the English alphabet only.