[net.micro.pc] how do you detect redirection

ken@elsie.UUCP (Ken Brown) (07/09/85)

The new Microsoft C compiler includes the isatty() function in the
standard library.  Unfortunately, it seems to work differently
than the UNIX function by the same name.
Apparently, under DOS isatty() can only detect the difference
between a device (any device) and a file.  Therefore, isatty()
returns true if a file handle is attached to the console or to
a printer, unlike the UNIX isatty() which returns false it the
handle is attached to a printer.

My question is, does anyone know how to detect whether or not
the standard output has been redirected to a printer port
(lpt1, etc.)?

I've looked at all of the information in the FILE structure.  I
can't find anything useful there.  I also looked at the DOS
function 44h (IOCTL), but apparently it does not distinguish different
devices in any way either.

Any clues would be appreciated.

Thanks in advance,
Ken Brown
Data Resources, Inc.
...!decvax!allegra!umcp-cs!elsie!ken

vch@rruxo.UUCP (V. Hatem) (07/14/85)

I've been able to detect the redirection of output to lpt1 by using the DOS
Organization: Bell Communications Research, Piscataway N.J.
Lines: 12

function 44h. Set al=0 to get device info, (ah to 44h, of course), interrupt,
(don't forget to set the bx to the file handle (I have the Computer
Innovations C86 Compiler and the handle for stdout is always 1)), and
when you get back, volia - (dx & 1) gives you a nice yes-or-no answer.

I get the impression that you tried this already and you're thinking 
I TRIED THAT! I don't know, it works for me! (DOS 2.10).

good luck,
Vince Hatem