How MS-DOS 6.22 Processes Pipe Operators
This article explains how MS-DOS 6.22 handles the pipe operator
(|) to pass data between two executable programs. Because
MS-DOS is a fundamentally single-tasking operating system, it cannot
execute processes concurrently or use true in-memory inter-process
communication like modern operating systems. Instead, the command
interpreter, COMMAND.COM, simulates piping by sequentially
executing programs and transferring data through temporary disk
files.
The Single-Tasking Limitation
Modern operating systems execute piped utilities simultaneously, using RAM-based FIFO buffers (pipes) to stream standard output from the first process directly into the standard input of the second. MS-DOS 6.22 cannot do this because the CPU operates in real mode, and the DOS kernel only allows one application to control the execution thread at a time. To overcome this limitation, DOS relies entirely on disk-based serialization.
Parsing and File Creation
When a user enters a command line such as PROG1 | PROG2,
COMMAND.COM parses the string and identifies the pipe
character. It splits the operation into two distinct phases:
- Locating Storage:
COMMAND.COMdetermines where to place intermediate data by checking the environment variables%TEMP%and%TMP%. If neither variable is set, it defaults to the root directory of the current drive. - Generating a Temporary File: Using DOS Interrupt 21h, Function 5Ah (Create Temporary File), the shell creates a uniquely named temporary file on the disk.
Step 1: Executing the First Utility
COMMAND.COM alters the system's file handles for the
first executable:
- The standard output handle (
STDOUT, handle 1) is redirected to point to the newly created temporary file. PROG1is loaded into conventional memory and executed to completion.- All output generated by
PROG1that would normally appear on the screen is written directly to the temporary file.
Because there is no multitasking, PROG2 does not load,
run, or receive any data while PROG1 is executing.
Step 2: Executing the Second Utility
Once PROG1 terminates and exits back to
COMMAND.COM, the shell prepares the second stage:
- The temporary file is rewound to the beginning.
- The standard input handle (
STDIN, handle 0) for the next process is redirected to read from this temporary file. PROG2is loaded into conventional memory, overwriting the memory previously occupied byPROG1.PROG2executes, reading the cached output ofPROG1as its own input until it reaches an End-of-File (EOF) marker.
Cleanup
When PROG2 finishes executing, control returns once more
to COMMAND.COM. The shell restores default input and output
handles back to the keyboard and display console (CON) and
deletes the temporary file from the disk. If a piping chain contains
more than two commands (e.g., PROG1 | PROG2 | PROG3),
MS-DOS repeats this sequential store-and-forward process, creating a new
temporary file for each successive stage.