AUTOEXEC and Batch Files
Outcome: you understand the two different things "autoexec" means here, and you can write a batch file that sets up a session and does real work — ECHO, SET, IF and all — with its results waiting in files you can check.
The [autoexec] section is DOSBox's
AUTOEXEC. On a real DOS machine,
AUTOEXEC.BAT ran at every boot. In
DOSBox the equivalent lines live at the
end of dosbox.conf: the factory
default file has exactly one,
SET BLASTER=A220 I7 D1 H5 T6 — the line
visible under the banner in chapter 4.
Mounts, PATH changes, and a final jump
into a program are usually added here.
Put a line in [autoexec] and it runs
every start, no exceptions; t06 proved
it by having the section write a marker
file unprompted.
A file called AUTOEXEC.BAT on a
mounted drive is just a batch file.
DOSBox does not run it merely for its
name. Called by name, though — or
CALLed from [autoexec] — it does the
same work. The lab's copy
(dosbox-lab/AUTOEXEC.BAT) sets PATH
to three directories and a GREETING
variable, and the proof was a later
SET, captured in t03: before the
batch, PATH=Z:\ and no GREETING; after
it, the new PATH and GREETING=Ledger
desk ready. The screen at that moment
is in dosbox-lab/dos-prompt.png.
And one honest limit, found by the lab
the direct way: the batch originally
also carried the classic PROMPT $T
$P$G line. DOSBox 0.74 has no PROMPT
command — the screen answered Illegal
command: PROMPT. (t04), the rest of the
batch ran, and the prompt stayed as it
always is in this build. If a batch file
from the old world begins with PROMPT,
that line will fail harmlessly here;
the forks in chapter 13 restore it.
Batch files do work. A .BAT file
is a list of commands with three small
powers: %1, %2… for the words typed
after its name; SET variables,
readable as %NAME%; and IF with
GOTO. The lab's LEDGER.BAT
(dosbox-lab/LEDGER.BAT) uses all of
them to write a stock card:
Stock card - small stores ledger
Item: Pencils, box of twelve
Count: 144
Status: full box, nothing to order
The last line was chosen — an IF
compared the count against 144 and a
second IF NOT held the alternative.
MENU.BAT dispatches on %1: MENU ADD
appends to a log, MENU LIST types it
back (t03). These are small, but they
are the whole grammar: most real-world
DOS batch files are these moves, longer.
The control trap, and its two keys.
A batch started plainly takes over:
control never returns to what invoked
it. The lab met this when a -c
"autoexec" in a startup chain swallowed
every command after it, including the
closing exit (t07). From DOS the fix
is CALL — CALL LEDGER runs the batch
and comes back. From outside, the clean
pattern is a driver batch: one file
that CALLs the others in order and ends
with EXIT, so the session closes
itself (the lab's driver is
dosbox-lab/T3.BAT). Its companion
quirk is in t07 too: redirecting a
CALL line creates the target file but
leaves it empty — the called batch's
output still goes to the screen.
Redirect a plain command before or
after the CALL instead.