Select the product you need help with
- Internet Explorer
- Windows Phone
- More products
Accepting Keyboard Input in Batch Files
Article ID: 77457 - View products that this article applies to.
This article was previously published under Q77457
The MS-DOS batch language facility does not provide a means for you to provide input to control program flow. All information input from you must be entered from the command line.
By using a short program created with the MS-DOS Debug utility, you can provide information at the time of batch file execution.
NOTE: Although the Debug program works with MS-DOS 6.0 or 6.2, it is not required. If you are using MS-DOS 6.0 or 6.2, type help choice at the MS-DOS command prompt for more information.
The Debug program at the end of this article will wait for you to input a character from the keyboard and set the value of "errorlevel" equal to the ASCII code value of the character entered. For a list of ASCII characters and their associated values, see the ANSI.SYS section in your MS-DOS manual.
Most keyboard characters are represented by only one code. However, the functions and ALT key combinations send two codes: a zero, followed by another code. The REPLY.COM program will set "errorlevel" equal to the second code passed. For example, the F8 key sends a zero followed by the value 66. This will be interpreted by REPLY.COM as the character "B," which has an ASCII value of 66.
REPLY.COM can be used within batch files to allow user input to control the flow of the program. For example, the following AUTOEXEC.BAT file allows you to determine whether or not to install a mouse driver during startup:
For more information about using the "errorlevel" environment variable, query on the following word in the Microsoft Knowledge Base:
@Echo off path=C:\DOS :Ask Echo Install Mouse Driver (y/n)? Reply If errorlevel 121 if not errorlevel 122 goto install If errorlevel 89 if not errorlevel 90 goto install If errorlevel 110 if not errorlevel 111 goto NoMouse If errorlevel 78 if not errorlevel 79 goto NoMouse goto ask :install c:\mouse\mouse :NoMouse cls ver
REPLY.COMTo create REPLY.COM, enter the text listed in the Instruction column. Press ENTER after each instruction. Do not enter the text listed in the Comment column; it is for your reference.
Instruction Comment ----------- ------- DEBUG Executes MS-DOS DEBUG utility -A 100 Begin assembling instructions at memory location 100 xxxx:0100 MOV AH,08 Get character input without echo xxxx:0102 INT 21 Perform MS-DOS service xxxx:0104 CMP AL,0 Compare AL with zero xxxx:0106 JNZ 010A If lead zero, get second code of character xxxx:0108 INT 21 Perform MS-DOS service xxxx:010A MOV AH,4C Terminate process with return code xxxx:010C INT 21 Perform MS-DOS service xxxx:010E <ENTER> -rcx CX 0000 :e -n REPLY.COM -w Writing 000E bytes -q
"Supercharging MS-DOS," pages 97-98, by Van Wolverton, Microsoft Press, 1989, 1991 (Updated for Version 4).
Article ID: 77457 - Last Review: May 12, 2003 - Revision: 2.0