Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!sol.ctr.columbia.edu!ucselx!math!lai From: lai@math.sdsu.edu (Henry Lai ) Newsgroups: comp.os.msdos.programmer Subject: Re: How to detect redirection? Summary: use isatty() Message-ID: <1990Aug8.012021.19429@ucselx.sdsu.edu> Date: 8 Aug 90 01:20:21 GMT References: <1426@wet.UUCP> Sender: news@ucselx.sdsu.edu (News Admin) Distribution: na Organization: San Diego State University, Mathematical Sciences Lines: 20 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? isatty (fileno (stdout)) will return zero if stdout has been redirected to a file. See the reference to isatty in your run-time library reference. -- Henry Lai Internet: lai@math.sdsu.edu UUCP: {mcgill-vision,sobeco,uunet}!batcave!lai