Path: utzoo!utgpu!water!watmath!clyde!att!rutgers!mailrus!cornell!uw-beaver!tektronix!tekcrl!tekgvs!toma
From: toma@tekgvs.GVS.TEK.COM (Tom Almy)
Newsgroups: comp.sys.ibm.pc
Subject: Re: How to determine stdin/out redirection
Message-ID: <3999@tekgvs.GVS.TEK.COM>
Date: 27 Sep 88 14:57:45 GMT
References: <9465@cup.portal.com>
Reply-To: toma@tekgvs.GVS.TEK.COM (Tom Almy)
Organization: Tektronix, Inc., Beaverton,  OR.
Lines: 38

In article <9465@cup.portal.com> Steve_R_Calwas@cup.portal.com writes:
>Is there a way for an application program to determine whether or not its
>standard input and/or standard output are being redirected?

I saw several followups to this that answered the question for C users
(or at least C users with certain unspecified C compilers).  But there
is a way to find out this information without resorting to the magic
of C.

Set AH to 44h, AL to 0, BX to the handle number (0 for standard input,
1 for standard output, 2 for standard error, 3 for AUX (com1), or 4 for
PRN (typically LPT1).  Execute an INT 21H.  If the carry flag is set
then an error code is in AX.  The only valid error for this operation
is 6 = handle not open.  If the carry flag is clear then all goes well.

DX will have the following information:

If bit 7 is 1, then a character device (keyboard, display, serial port,
or parallel port) and:
Bit 14 -- Can process control strings (not too interesting)
Bit 6 -- End of file on input
Bit 5 -- binary/raw mode (no special control character handling)
Bit 3 -- clock device
BIt 2 -- NUL device
bit 1 -- console output device
bit 0 -- console input device

If bit 7 is 0, then it is a block device (disk) and:
bit 6 -- file has been written
bits 0-5 -- drive number, 0 = A, 1 = B, etc.



There, that's more information than just "isatty".

Tom Almy
toma@tekgvs.TEK.COM
Standard Disclaimers Apply