in reply to Porting Perl 5.6 to Perl 5.8 issue with self-tie
#!/usr/bin/perl -wl $| = 1; # unbuffered output print $$; for(1,2){ open SAVEOUT,">&STDOUT"; my $pid = open STDOUT,"| tee log_$_"; open STDERR, ">&STDOUT"; print "this goes to STDOUT (log_$_)"; warn "This goes to STDERR (log_$_)"; sleep 1; print "killing $pid"; kill 15, $pid; close STDOUT; close STDERR; open STDOUT,">&SAVEOUT"; } __END__ Name "main::SAVEOUT" used only once: possible typo at tee.pl line 4. 14781 this goes to STDOUT (log_1) This goes to STDERR (log_1) at tee.pl line 8. killing 14782 this goes to STDOUT (log_2) This goes to STDERR (log_2) at tee.pl line 8.
$ cat log_1 log_2 this goes to STDOUT (log_1) This goes to STDERR (log_1) at tee.pl line 8. this goes to STDOUT (log_2) This goes to STDERR (log_2) at tee.pl line 8.
Of course, if you need to restore STDERR later, save that too. See open. Note that if you remove the sleep 1 line in the above code you will likely not see any output, because then the tee process gets killed too soon.
--shmem
update: fixed inconsistencies stemming from putting a oneliner into a file..
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Porting Perl 5.6 to Perl 5.8 issue with self-tie
by fwashbur (Sexton) on Dec 11, 2006 at 22:25 UTC | |
by fwashbur (Sexton) on Dec 11, 2006 at 23:45 UTC | |
by shmem (Chancellor) on Dec 14, 2006 at 18:39 UTC |