Can I get back stdout after redirection?

pefv700 at perv.pe.utexas.edu pefv700 at perv.pe.utexas.edu
Wed May 1 09:02:32 AEST 1991


The subject says it all.

>From what I understand, with

% cmd > file

the typical shell will do something like (omitting error checking)

    fd = fopen("file", "w");
    close(1);
    dup(fd);

Since the shell has already closed stdout's file descriptor, is it not
possible to reopen it?  (Also, how did stdout get opened in the first
place?  The shell inherited it from its parent, didn't it?)

Thanks,

Chris



More information about the Comp.unix.programmer mailing list