Nested Batch CALL Limits in MS-DOS 6.22
In MS-DOS 6.22, the maximum depth for nesting batch files using the
CALL command is not defined by a hardcoded numeric limit.
Instead, the limitation is dictated by available conventional memory and
the internal batch context storage managed by COMMAND.COM.
This article explains how MS-DOS handles batch nesting, the memory
mechanics involved, and the secondary system constraints that can halt
execution.
How COMMAND.COM Manages the CALL Command
When a batch file uses the CALL statement to invoke
another script, COMMAND.COM must preserve the state of the
calling batch file so execution can resume once the secondary script
finishes. To do this, the command interpreter creates a batch context
structure in memory. This block stores critical execution state data,
including:
- The fully qualified path and filename of the calling batch file
- The current file pointer offset (to resume reading at the correct line)
- The original command-line arguments (
%0through%9) - Current redirection settings and batch-specific flags
The Primary Limitation: Available Conventional Memory
Because there is no fixed software counter capping recursion depth, the primary barrier is the amount of free conventional memory (the lower 640 KB of RAM).
Each nested CALL allocates an additional context block
via standard DOS memory allocation routines. As scripts continue to
nest, these context structures gradually consume the memory pool. If
nested calls continue indefinitely—such as in an infinite recursion
loop—MS-DOS will eventually exhaust conventional memory and return an
Insufficient memory error, aborting execution. Under
typical memory configurations with minimal TSR programs loaded, this
architecture allows scripts to nest hundreds of levels deep before
running out of memory.
Secondary Constraints: File Handles and Environment Space
While free memory is the primary constraint, other system configuration parameters can also trigger limits:
- File Handles (
FILESsetting): MS-DOS re-reads batch files as they execute. Depending on execution state and nested redirections, reaching the handle limit configured by theFILES=directive inCONFIG.SYScan cause nested calls to fail. - Stack Space (
STACKSsetting): Deep recursion combined with heavy hardware interrupt activity can stress DOS internal data stacks, potentially leading to system instability or anInternal stack overflowhalt ifSTACKSis under-configured. - Environment Size: If nested batch routines
dynamically set environment variables at each level, the batch chain
will fail prematurely with an
Out of environment spacewarning once the environment block size specified by the/Eswitch inSHELL=is exhausted.