28: How does one
detect whether input (or output) is redirected?
A: As we know input to
a program can come from a file, from the
console, or from a pipe or redirection. Examples of the latter are
type text.dat | program
program < text.dat
A Turbo Pascal program can be made to detect the redirections
using
Interrupt 21Hex, function 44Hex, subfunction 00Hex. See PC
Magazine
April 16, 1991, p. 374 for the code, and Duncan (1988), Advanced
MS-DOS Programming, pp. 412-413 for more information.
Alternatively,
you can utilize the preprogrammed routines
PIPEDIFN Is the standard input from redirection
PIPEDNFN Is the standard output redirected to nul
PIPEDOFN Is the standard output redirected
from my ftp://garbo.uwasa.fi/pc/ts/tspa3470.zip units.