File Handle
Starting with DOS 2.0, a set of UNIX-like file functions were added to the
DOS repertoire. When you open a file, DOS passes back a 16-bit value
called a file handle. Thereafter, when you read, write, seek a position,
or close the file, you refer to it by its handle.
One nice feature is that you can refer to certain devices as if they were
disk files by using one of the reserved DOS handles:
Pre-defined DOS handles
Handle Description
▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
0000H Standard Input Device (usually the keyboard)
0001H Standard Output Device (usually the screen)
0002H Standard Error Device (always CON--the screen. Use for messages)
0003H Standard AUX Device (AUX first serial port--COM1)
0004H Standard Printer (PRN first parallel printer port--LPT1)
Notes: ■ Standard handles are automatically opened when your program
starts:
• Use fn 3fH and 40H to read and write.
• Close one or more standard handles if an open fails due to
lack of handles (or use fn 67H to increase the available
number of handles).
• One quick sanity check during debugging: The first file you
open should generally be assigned handle # 5.
■ You can redirect Standard Input and Standard Output handles to
a text file or another device. See I/O Redirection for
details.
■ You can flush a standard handle via fn 68H (commit file)
See Also: Handle-Oriented File I/O
Standard I/O
Config.Sys (FILES= setting)
-♦-