*STDIN = $c; # $c is child socket
Well, no wonder you have problems. Using symbol table globs to copy around file handles is usually a pretty bad idea, in my experience.
I can't figure out how to ensure that I always open fileno 1
open covers this. You close fileno 1 and then immediately reopen STDOUT and Perl even goes to a little extra effort to make sure fileno 1 is what you get (and this is documented). But ">&=" doesn't "open" any file descriptors, it causes a file handle to be associated with an already-open file descriptor. You want ">&" instead (which dup()s a file descriptor).
There is even an example of how to redirect STDOUT and STDERR (and then restore them) in the open documentation. To do STDIN andn STDOUT and not worry about restoring them, you should use something like:
open( STDIN, "<&".fileno($c) ) # also closes old STDIN or die "Can't redirect STDIN from socket: $!\n"; open( STDOUT, ">&".fileno($c) ) # also closes old STDOUT or die "Can't redirect STDOUT to socket: $!\n";
- tye
In reply to Re: STDOUT changing descritpors (open, no =)
by tye
in thread STDOUT changing descritpors
by suaveant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |