Path: utzoo!attcan!uunet!virtech!cpcahil From: cpcahil@virtech.UUCP (Conor P. Cahill) Newsgroups: comp.unix.questions Subject: Re: How does man know? Summary: isatty() is the answer Keywords: more, io redirection Message-ID: <1203@virtech.UUCP> Date: 28 Sep 89 01:08:32 GMT References: <319@massey.ac.nz> Organization: Virtual Technologies Inc Lines: 31 In article <319@massey.ac.nz>, ARaman@massey.ac.nz (A.V. Raman) writes: > When I do a man sh, I have to page down a few times or /search > to get to the page where chdir, for example, is discussed. > However when I pipe the output of man into another command or > redirect it into a file, man seems to somehow sense that it is now > writing into a pipe rather than into a terminal because it does > not pause after each screenful asking for keyboard input. This is because man uses isatty() to determine if the file descriptor associated with stdout is a tty filedes or not. If it is, the output gets processed through a pager, otherwise it just dumps the output. > My guess is that when shell forks and execs man, it passes down the > file descriptor of stdin and stdout, which however, are now different > from the actual stdin and stdout and man uses (stdout->_file == 1)? > to determine whether the output is a tty or not (yuck). But it does > seem to be very convenient though. Nope. stdout->_file is still equal to 1. The FILE pointer std* is not passed to the child program, the file descriptors are. The stdio library always attatches stdout to file descriptor 1. You should note that this does not violate the "basic philosophy of transparancy in UNIX" because it is transparent. The program does have the ability to break through the transparancy, but the transparancy is there. -- +-----------------------------------------------------------------------+ | Conor P. Cahill uunet!virtech!cpcahil 703-430-9247 ! | Virtual Technologies Inc., P. O. Box 876, Sterling, VA 22170 | +-----------------------------------------------------------------------+