MS-DOS 6.22 Executable Search Order: COM, EXE, BAT
When a user enters a command at the command prompt in MS-DOS 6.22
without specifying a file extension, the operating system initiates a
strict, deterministic sequence to locate and execute the program. This
process involves evaluating internal commands, searching the active
working directory, scanning directories configured in the system's
PATH environment variable, and applying a specific
extension hierarchy: .COM, followed by .EXE,
and finally .BAT.
1. Internal Command Check
Before accessing the disk to look for files with .COM,
.EXE, or .BAT extensions, MS-DOS checks
whether the typed command is an internal command. Internal commands
(such as DIR, COPY, DEL, or
CD) reside directly inside COMMAND.COM and run
entirely from memory. If a match is found, MS-DOS executes it
immediately and stops the search.
2. Current Directory Search
If the command is not built into COMMAND.COM, MS-DOS
begins searching the storage drive. It starts in the current working
directory. If the user did not include a specific file extension with
the command name, MS-DOS looks for matching file names using the
following hardcoded extension priority:
.COM(Command File): MS-DOS looks first for a file with the.COMextension. These are simple binary executables loaded directly into a single 64KB memory segment..EXE(Executable File): If no.COMfile is present, MS-DOS searches for an.EXEfile. These are relocatable executables that can handle multiple memory segments..BAT(Batch File): If neither a.COMnor an.EXEfile exists, MS-DOS searches for a plain-text.BATfile to execute commands sequentially through the command interpreter.
If a file named TEST.COM, TEST.EXE, and
TEST.BAT all exist in the same directory and the user types
TEST, MS-DOS will always execute TEST.COM.
3. The PATH Variable Traversal
If the file is not found in the current directory, MS-DOS consults
the PATH environment variable defined in the system's
memory (typically set in AUTOEXEC.BAT).
The operating system checks the directories in the PATH
string sequentially from left to right:
- MS-DOS moves to the first directory specified in the
PATH. - In that directory, it applies the exact same extension order:
.COM, then.EXE, then.BAT. - If a match is found, the file executes, and the search terminates.
- If no match is found, MS-DOS advances to the next directory in the
PATHlist and repeats the three-step extension search.
Because MS-DOS evaluates the entire extension hierarchy within a
single directory before moving to the next directory, a
.BAT file in an earlier PATH directory takes
priority over an .EXE or .COM file in a later
PATH directory.
4. Explicit File Extensions
If the user types the command with an explicit extension (for
example, TEST.EXE), MS-DOS skips the extension hierarchy
logic. It searches the current directory specifically for
TEST.EXE. If not found, it traverses the PATH
directories from left to right looking exclusively for
TEST.EXE. It will not attempt to run TEST.COM
or TEST.BAT.
5. Search Failure
If MS-DOS reaches the end of the PATH variable without
finding a matching .COM, .EXE, or
.BAT file, it halts the search and outputs the default
error message:
Bad command or file name