MS-DOS 6.22 Batch File PAUSE Execution Explained
This article examines the internal mechanics of how MS-DOS 6.22
processes batch files when encountering the PAUSE command.
It details how the command processor (COMMAND.COM) suspends
script interpretation, displays the prompt, listens for hardware
interrupts through DOS system calls, and handles execution resumption or
user termination.
In MS-DOS 6.22, batch files (.BAT) are not compiled or
loaded entirely into memory. Instead, the command interpreter,
COMMAND.COM, processes batch files dynamically on a
line-by-line basis. When executing a script, COMMAND.COM
keeps track of the file’s location and the current byte offset. It opens
the batch file, reads a single line into its internal command buffer,
updates its file seek pointer, closes the file handle (in most standard
operations to allow floppy disk swapping or prevent locking), and
executes the parsed line.
When the interpreter parses the internal command PAUSE,
it immediately suspends the sequential execution loop. By default,
PAUSE writes the standard message
Press any key to continue . . . to standard output
(STDOUT). This string is written using DOS Interrupt 21h,
Function 09h (Print String) or Function 02h (Character Output). If
standard output has been redirected (for example,
PAUSE > NUL), the text generation is diverted, but the
execution halting mechanism remains identical.
Once the prompt is output, COMMAND.COM explicitly halts
batch progression by requesting a blocking character input from the
operating system. It does this by calling DOS Interrupt 21h, Function
08h (Character Input Without Echo) or Function 07h (Direct Character
Input Without Echo). Under the hood, this DOS service calls BIOS
Interrupt 16h, Function 00h (Read Keystroke).
At this point, the CPU enters an idle state or services other hardware interrupts while the operating system waits for keyboard input. The batch processing engine does not poll in a busy loop; it remains blocked until an electrical signal from the keyboard generates a hardware interrupt (IRQ 1, mapped to INT 09h). The keyboard interrupt handler converts the scancode into an ASCII character and places it into the circular keyboard buffer in the BIOS data area (0040:001Eh).
During this suspended state, MS-DOS evaluates input for termination
signals. If the user presses the Ctrl+C or
Ctrl+Break combination, the DOS interrupt handler fires
Interrupt 23h. When triggered, the normal PAUSE routine
aborts, and DOS outputs the prompt:
Terminate batch job (Y/N)?. If the user inputs
Y, COMMAND.COM discards the batch environment
context, resets its internal state, frees any allocated batch memory
structures, and returns to the interactive command prompt. If the user
inputs N, execution resumes, and PAUSE
continues waiting for an ordinary keypress.
When a standard keystroke occurs, BIOS INT 16h retrieves the
character from the buffer and returns control to DOS INT 21h, Function
08h. The PAUSE command simply discards the retrieved ASCII
code and scancode without processing or storing the value.
With the blocking function completed, control returns to the main
batch interpretation loop of COMMAND.COM. The interpreter
reopens the batch file, uses DOS Interrupt 21h, Function 42h (LSEEK) to
advance to the previously stored byte offset, reads the next line of
text into memory, and proceeds with the remainder of the script.