The dup2(2) system calls simply duplicates to file descriptor. Also, I could be wrong, but when a child process starts it inherits all the parent's open file descriptors. I don't believe that the parent shell closes 0, 1, or 2 at all. The freopen(3) C function does close the open file descriptor associated with the FILE structure, and then opens a new file to be associated with it. On 7 Jun 2002 at 14:40, [EMAIL PROTECTED] wrote:
> > In a message dated: Fri, 07 Jun 2002 14:26:34 EDT > Benjamin Scott said: > > >On Fri, 7 Jun 2002, at 2:00pm, [EMAIL PROTECTED] wrote: > >> Ahm, I don't think you can, since the shell is sending to STDOUT in this > >> case, and STDOUT has been redirected at *shell* level to be someplace > >> other than STDOUT; in this case, a file. > > > > STDOUT is simply file descriptor 1. (STDIN is FD 0, STDERR is FD 2.) > >All a shell does when it sets up redirection is close the appropriate FD, > >and then re-open it on another file (using the dup2(2) system call (I > >think)). The program being redirected simply outputs to the appropriate FD. > > > > As Michael O'Donnell points out, you can use the -t "test" to determine if > >a FD number is a tty or not. I expect that simply makes use of the > >"isatty(3)" library call. > > Right, but aren't there essentially 2 STDOUTs here? What the script > thinks is STDOUT and what the parent shell thinks is STDOUT? > In other words, the shell script has it's own copies of FDs 0,1, and 2 > separate from that of the parent shell which spawned it. The parent > shell is being told take all output from this script and throw it > into this file. Whereas the script is being told, throw everything > to STDOUT. > > Oh, wait, you just mentioned dup(2), never mind, I think I just > realized the error of my reasoning (or lack thereof :) > -- > > Seeya, > Paul > ---- > It may look like I'm just sitting here doing nothing, > but I'm really actively waiting for all my problems to go away. > > If you're not having fun, you're not doing it right! > > > > ***************************************************************** > To unsubscribe from this list, send mail to [EMAIL PROTECTED] > with the text 'unsubscribe gnhlug' in the message body. > ***************************************************************** -- Jerry Feldman <[EMAIL PROTECTED]> Associate Director Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9 ***************************************************************** To unsubscribe from this list, send mail to [EMAIL PROTECTED] with the text 'unsubscribe gnhlug' in the message body. *****************************************************************
