Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!ncar!midway!gsbsun!valley From: valley@gsbsun.uchicago.edu (Doug Dougherty) Newsgroups: comp.os.msdos.programmer Subject: Re: Sensing STDOUT redirection in C Keywords: STDOUT, Redirection, MSDOS Message-ID: <1991Apr18.185454.25215@midway.uchicago.edu> Date: 18 Apr 91 18:54:54 GMT References: <1991Apr16.145847.20316@midway.uchicago.edu> <1991Apr18.165820.6035@amc.com> Sender: news@midway.uchicago.edu (NewsMistress) Organization: University of Chicago Lines: 27 jwbirdsa@amc.com (James Birdsall) writes: >In article <1991Apr16.145847.20316@midway.uchicago.edu> valley@gsbsun.uchicago.edu (Doug Dougherty) writes: >>collinsa@p4.cs.man.ac.uk (Adrian Collins) writes: >>>Does anybody know how to sense whether output redirection has been used >>>on the command line? >>isatty(1) >>(Works in Turbo C) > Well, almost. isatty() returns true if the supplied handle is the >console *or* a printer or serial port. Determining whether the handle is >actually the console or not requires an ioctl() and checking some bits. Someone else pointed this out to me in email as well. Yes, this is only a 90% solution. Actually, I think, in DOS, isatty() returns true iff the handle refers to a *character device* (my emphasis). Which includes of course, not only CON, COMx, PRN, but also NUL as well as any installed character devices. Still, I think it handles most of the occurrences, since what most users are concerned about is redirection to a file anyway. And the original poster did refer to TurboC specifically, and isatty() does have the virtue of being a regular TC built-in function. -- (Another fine mess brought to you by valley@gsbsun.uchicago.edu)