🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #1811

Re: How to detect redirection?

#1811
From: Steve Resnick
Date: Wed, 08 Aug 1990 00:43
29 lines
2096 bytes
In article <1426@wet.UUCP> naga@wet.UUCP (Peter Davidson) writes:
>Let's say X.EXE is a program written in (Microsoft) C which
>calls printf() to output to the monitor.  Invoking X using
>X > PRN (or some file) redirects output to the printer (or file).
>Suppose that X does something (such as writing directly to video RAM)
>which it would not like to do if output has been redirected as above?
>How can it tell?  One solution is: Use printf() to output a charactr
>and then peek in the video RAM to see if the character went there
>(if so, no redirection).  The disadvantage is that, if redirection
>is in effect, a character (perhaps only a space) is sent to the
>printer (or file).  Is there a more elegant way to tell whether
>output has been redirected? 

That's not too elegant a solution: there is no guarantee that printf will
put the character in a specific memory location, and if I/O is redirected,
that character may already be on the screen. In C the easiest way to determine
if I/O has been redirected is to call isatty(fileno(stdout)) this returns
non-zero if the file descriptor associated with stdout is a character device.
The problem with this is the redirection may be associated with another
character device (AUX, PRN, etc). Is there an easy way to do THIS?

Cheers! 
Steve

-- 
----------------------------------------------------------------------------
steve.resnick@f105.n143.z1@FIDONET.ORG #include<std_disclaimer.h>
Flames, grammar errors, spelling errrors >/dev/nul
----------------------------------------------------------------------------
Technical Details
Message-ID: <1990Aug8.004304.26989@Octopus.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!sdd.hp.com!decwrl!nsc!pyramid!octopus!stever
References: <1426@wet.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!sdd.hp.com!decwrl!nsc!pyramid!octopus!stever
From: stever@Octopus.COM (Steve Resnick )
Newsgroups: comp.os.msdos.programmer
Subject: Re: How to detect redirection?
Message-ID: <1990Aug8.004304.26989@Octopus.COM>
Date: 8 Aug 90 00:43:04 GMT
References: <1426@wet.UUCP>
Reply-To: stever@octopus.UUCP (Steve Resnick )
Distribution: na
Organization: Octopus Enterprises, Cupertino CA
Lines: 29