How do you make a batch file accept 1-char keyboard input WITHOUThaving to also press carriage return?
On 29/05/2018 01:13, Bob J Jones wrote:
How do you make a batch file accept single-character keyboard input
WITHOUT having to also press carriage return?
PAUSE echoes "Press a key to continue ..." and waits for the user to
press any single key.
However, if you want the user to make a choice, then, surprise,
surprise, use the CHOICE command, as in the following W9x example (the
CHOICE command is still available in W7, but its parameters may alter
somewhat between versions of Windows):
CLS
ECHO %Title%
ECHO.
ECHO 0 Quit
ECHO 1 Partition Hard Disk
ECHO 2 Format Hard Disk
ECHO 3 Configure PC Or Netcard
ECHO 4 Image PC To Or From Server
ECHO 5 Exit To DOS
ECHO.
CHOICE /C:012345 /N "Please choose [012345]: "
ECHO.
IF ERRORLEVEL 1 SET Choice=ExitDos
IF ERRORLEVEL 2 SET Choice=StdFDisk
IF ERRORLEVEL 3 SET Choice=Format
IF ERRORLEVEL 4 SET Choice=Setup
IF ERRORLEVEL 5 SET Choice=Image
IF ERRORLEVEL 6 SET Choice=ExitDos
GOTO %Choice%
See also CHOICE /? for help.
|