Xref: utzoo comp.unix.questions:11910 comp.unix.xenix:5139 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!ames!sgi!daisy!klee From: klee@daisy.UUCP (Ken Lee) Newsgroups: comp.unix.questions,comp.unix.xenix Subject: Re: How to determine file being redirected to in C Message-ID: <2775@daisy.UUCP> Date: 28 Feb 89 01:38:45 GMT References: <10@sherpa.UUCP> Reply-To: klee@daisy.UUCP (Ken Lee) Distribution: na Organization: Daisy Systems Corp., Mountain View, Ca. Lines: 15 In article <10@sherpa.UUCP> rac@sherpa.UUCP (Roger A. Cornelius) writes: > Anyway, can someone tell me how to determine (in C) >if output is being redirected, or more precisely, how to determine the >file output is being redirected to. In BSD UNIX, you can fstat(2) stdout to determine if the output is a file or terminal (or whatever) and, what inode number it has. Since several file names can have the same inode, you can't tell exactly what file name was specified, but the inode number should be enough information for cat and other such applications. Ken Lee -- klee@daisy.uucp Daisy Systems Corp., Interactive Graphics Tools Dept.