Path: utzoo!utgpu!water!watmath!clyde!att!rutgers!mailrus!cornell!uw-beaver!tektronix!gvgpsa!gvgspd!mrk
From: mrk@gvgspd.GVG.TEK.COM (Michael R. Kesti)
Newsgroups: comp.sys.ibm.pc
Subject: Re: How to determine stdin/out redirection
Summary: Here's how in assembler
Message-ID: <630@gvgspd.GVG.TEK.COM>
Date: 27 Sep 88 19:43:39 GMT
References: <9465@cup.portal.com>
Reply-To: mrk@gvgspd.GVG.TEK.COM (Michael R. Kesti)
Organization: The Grass Valley Group, Grass Valley, CA
Lines: 42

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?

Well, lots of people seem to know how to do this in C, but if you wanted
to do it in assembler, here's how I determined the status of stdout in a
replacement for uSoft's (brain dead) MORE command that I wrote.  The
technique is similiar for stdin.

The information is available through the IOCTL function (44H) of the DOS
function interrupt (21H).  The following code demonstrates this:

	mov	ah,44H			; I/O control function
	mov	al,0			; get device information subfunction
	mov	bx,01H			; standard output device
	int	21H			; get standard output information
	test	dx,0000000010000000B	; is standard output a file?
	jz	init_05			; yes - set flag

	jmp	init_10			; no - clear flag

init_05:
	mov	file_flag,0FFH		; indicate standard output is a file
	jmp	init_15			; continue

init_10:
	mov	file_flag,00H		; indicate standard output is a pipe

init_15:


I got this info from Norton's _Programmer's Guide to the IBM PC_.  See
chapter 17, pages 311-313.

One more note - Norton indicates this wasn't available prior to version 2.0.

-- 
============================================================================
Michael Kesti  Grass Valley Group, Inc. | "Like one and one don't make two,
    @gvgspd.GVG.TEK.COM                 |  one and one make one."
    !tektronix!gvgpsa!gvgspd!mrk        |         - The Who, Bargain