MS-DOS 6.22 Standard Error Output Explained
This article examines how MS-DOS 6.22 directs and processes system
error messages through standard error streams. It covers the
architectural use of reserved file handle 2 (STDERR), the
system-level MS-DOS interrupts used to transmit error text, how MS-DOS
prevents diagnostic messages from being redirected alongside normal
output, and the distinct separation between standard software errors and
low-level critical hardware errors.
The MS-DOS File Handle Architecture
MS-DOS 6.22 manages input and output operations through an array of predefined file handles initialized whenever a program launches. Five standard handles are permanently reserved:
- Handle 0 (
STDIN): Standard input (defaults to the keyboard/CON). - Handle 1 (
STDOUT): Standard output (defaults to the monitor/CON). - Handle 2 (
STDERR): Standard error (defaults to the monitor/CON). - Handle 3 (
STDAUX): Standard auxiliary (serial communications/AUX). - Handle 4 (
STDPRN): Standard printer (parallel printer/PRN).
When an MS-DOS utility or internal command encounters an operational
error, it writes diagnostic text directly to Handle 2
(STDERR) rather than Handle 1 (STDOUT).
Writing via Interrupt 21h, Function 40h
Software running under MS-DOS 6.22 writes to STDERR
using the MS-DOS API dispatcher, Interrupt 21h. The
operating system provides Function 40h (Write to File
or Device) to transmit bytes to any active file or stream handle.
To output an error message, the calling application configures the CPU registers as follows:
AH: Set to40h(the function code for writing).BX: Set to0002h(the predefined handle forSTDERR).CX: Set to the length of the error message string in bytes.DS:DX: A pointer to the memory buffer containing the ASCII text of the error.
Executing INT 21h signals the MS-DOS kernel to process
the request. The kernel inspects the Job File Table (JFT) within the
program's Program Segment Prefix (PSP). Entry 2 of the JFT points
directly to the system device entry for CON (the console
driver), which immediately passes the characters to the screen via the
system BIOS (specifically INT 10h).
Stream Separation and Redirection Immunity
The core purpose of isolating STDERR on Handle 2 in
MS-DOS 6.22 is redirection control. The default command interpreter,
COMMAND.COM, only provides native syntax to redirect
standard input and output:
PROGRAM.EXE > OUTPUT.TXT
In this scenario, COMMAND.COM duplicates the file handle
for OUTPUT.TXT over Handle 1 (STDOUT). Handle
2 (STDERR), however, remains untouched and still references
the CON device. As a result, informational and
computational output is captured in the file, while error strings bypass
the destination file and render directly to the user's monitor.
Unlike modern Windows command processors (cmd.exe),
MS-DOS 6.22 has no built-in syntax (such as 2>) to
redirect Handle 2 from the command line. An application can internally
redirect Handle 2 using Function 46h (Force Duplicate
Handle), but the shell itself maintains STDERR as an
unredirected path straight to the display.
Critical System Errors vs. Standard Errors
MS-DOS 6.22 makes a technical distinction between software errors (such as file not found or invalid syntax) and critical system/hardware failures (such as unreadable floppy sectors or drive-door-open events).
While software errors use Handle 2 via Function 40h, critical I/O errors trigger Interrupt 24h (the Critical Error Handler). When a device driver flags a critical error to the MS-DOS kernel:
- MS-DOS saves the CPU registers and constructs an error code in the
AHandDIregisters. - The kernel invokes
INT 24h. - The default
INT 24hhandler inCOMMAND.COMhalts normal execution, overrides standard device handles, and directly prints the prompt:Abort, Retry, Fail?to the console using low-level console functions (Function 09h or BIOS video calls). - User keystrokes are received via standard BIOS calls, completely bypassing standard error handle logic to ensure the prompt is displayed even if standard streams are broken or missing.