🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: How to detect redirection?

#1856
From: Larry A. Shurr
Date: Wed, 08 Aug 1990 17:14
30 lines
2001 bytes
In article <1990Aug8.030621.24021@world.std.com> jstone@world.std.com (Jeffrey R Stone) writes:
}lai@math.sdsu.edu (Henry Lai ) writes:
}
}}In article <1426@wet.UUCP> naga@wet.UUCP (Peter Davidson) writes:
}    [ question about how to detect that stdout 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.

}According to Turbo C's library reference, isatty() returns TRUE if 
}it argument file pointer is a character devuce - A tty - not necessarily
}THE tty.

As does Turbo C++.  I don't have the canonical list of interrupts or any
other suitable reference in front of me, but if memory serves, you can
do an ioctl on fileno(stdout) to get device information which includes a
bit which identifies whether or not the device is the console.  Presum-
ably, you can assume that if fileno(stdout) is a file or is a character
device other than the console, then stdout is redirected.  Borland
provides an ioctl() function you can use for this.

I think that the original question referred to MicroSoft C, but its
isatty() may have the same characteristic as Borland's.

regards, Larry
-- 
Larry A. Shurr (cbnmva!las@att.ATT.COM or att!cbnmva!las)
The end of the world has been delayed due to a shortage of trumpet players.
(The above reflects my opinions, not those of AGS or AT&T, but you knew that.)
Technical Details
Message-ID: <1990Aug8.171401.20830@cbnews.att.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!mcgill-vision!snorkelwacker!usc!rutgers!att!cbnews!shurr
References: <1426@wet.UUCP> <1990Aug8.012021.19429@ucselx.sdsu.edu> <1990Aug8.030621.24021@world.std.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!mcgill-vision!snorkelwacker!usc!rutgers!att!cbnews!shurr
From: shurr@cbnews.att.com (Larry A. Shurr)
Newsgroups: comp.os.msdos.programmer
Subject: Re: How to detect redirection?
Message-ID: <1990Aug8.171401.20830@cbnews.att.com>
Date: 8 Aug 90 17:14:01 GMT
References: <1426@wet.UUCP> <1990Aug8.012021.19429@ucselx.sdsu.edu> <1990Aug8.030621.24021@world.std.com>
Distribution: na
Organization: AT&T Bell Laboratories, Columbus, OH (actually an AGS consultant)
Lines: 30