Passing Command Parameters to BASIC in MS-DOS 6.22
MS-DOS 6.22 relies on QBasic 1.1 as its default BASIC interpreter,
executing scripts via the command-line interface using the
/RUN switch. While standalone development environments like
QuickBASIC natively supported command parameter retrieval through
internal functions, the stripped-down QBasic interpreter bundled with
MS-DOS 6.22 introduces specific constraints for parameter passing. This
article examines the default execution mechanism of BASIC under MS-DOS
6.22, the technical limitations of its interpreter, and the standard
workarounds used to pass arguments from the DOS prompt into a
script.
The Invocation Mechanism
In MS-DOS 6.22, running a BASIC program directly from the command prompt or a batch file uses the following standard syntax:
QBASIC /RUN script.bas
The /RUN flag instructs the interpreter to load
script.bas, execute the code immediately, and exit back to
the DOS prompt upon completion rather than dropping the user into the
interactive development environment.
However, MS-DOS 6.22 does not pass any trailing arguments entered after the file name directly to the script. If a user attempts to execute:
QBASIC /RUN script.bas ARG1 ARG2
The QBASIC.EXE binary attempts to parse
ARG1 and ARG2 as internal command-line
switches or additional file targets. This results in syntax errors or
file-loading failures before the script executes.
The Missing COMMAND$
Function
In full commercial releases such as Microsoft QuickBASIC 4.5,
developers retrieved command-line parameters using the built-in
COMMAND$ string function, which read the parameter string
stored in the program's Program Segment Prefix (PSP) at offset
80h.
To minimize disk usage and protect the commercial market for
QuickBASIC, Microsoft shipped MS-DOS 6.22 with a reduced version of the
environment: QBasic 1.1. In this version, Microsoft removed the
COMMAND$ function entirely, along with compiler functions
and the ENVIRON$ function. As a result, there is no native
BASIC syntax in MS-DOS 6.22 to directly read arguments supplied to the
DOS command line.
Workarounds for Parameter Passing
Because native parameter passing is unsupported by QBasic 1.1, developers in the MS-DOS 6.22 environment relied on specific workarounds to transfer command parameters into their scripts.
1. The Batch File and Temporary File Method
The standard method involves wrapping the QBasic execution inside an
MS-DOS batch file (.BAT). The batch file captures
command-line arguments using DOS parameter placeholders
(%1, %2, etc.) and redirects them into a
temporary file.
RUNPROG.BAT:
@ECHO OFF
ECHO %1 %2 %3 > PARAMS.TMP
QBASIC /RUN SCRIPT.BAS
DEL PARAMS.TMPSCRIPT.BAS:
OPEN "PARAMS.TMP" FOR INPUT AS #1
LINE INPUT #1, Args$
CLOSE #1
PRINT "Arguments received: "; Args$
This method remains the most compatible way to feed external inputs to a script without modifying system memory.
2. Reading the Master Environment Block
While QBasic 1.1 lacks the ENVIRON$ function to read
variables set by SET VAR=VALUE, low-level memory inspection
allows access to the MS-DOS environment block.
By utilizing the DEF SEG statement and
PEEK, a script can traverse the DOS memory control blocks
(MCB) to locate the master environment segment. A batch file sets an
environment variable, and the script iterates through DOS memory
starting from the segment found in the Interrupt Vector Table or DOS
list of lists. Once the variable name is matched as an ASCII sequence,
the script reads the accompanying parameter value.
3. Low-Level PSP Interception
Advanced implementations utilized machine code injected into memory
via the CALL ABSOLUTE statement. Although
QBASIC.EXE acts as the active process, machine code
routines can trace back the DOS process hierarchy to find the parent
shell (COMMAND.COM), locate the calling command buffer, and extract the
parameters originally entered by the user. Due to the complexity and
instability across different memory configurations, file redirection
remained the dominant convention.