Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Best Way to Redirect STDERR to a Scalar

by Fletch (Chancellor)
on Sep 13, 2003 at 22:27 UTC ( #291300=note: print w/ replies, xml ) Need Help??


in reply to Best Way to Redirect STDERR to a Scalar

You might want to check into IO::Scalar.


Comment on Re: Best Way to Redirect STDERR to a Scalar
Replies are listed 'Best First'.
Re: Re: Best Way to Redirect STDERR to a Scalar
by Mr. Muskrat (Abbot) on Sep 14, 2003 at 01:09 UTC

    I should have mentioned that I tried IO::Scalar. The following code causes a page fault in perl56.dll.

    use IO::Scalar; print "Trying ioscalar...\n"; my $io = ioscalar(); print "Finished with ioscalar.\n"; print $io; print "Testing STDERR...\n"; print STDERR "(STDERR) can you hear me now?\n"; sub ioscalar { my $data; *oldfh = select STDERR; # save STDERR print "STDERR saved.\n"; my $SH = new IO::Scalar \$data; print "\$SH created.\n"; open(STDERR, '>', $SH) || die "Can't redirect STDERR to the IO::Scal +ar, $!"; print "STDERR redirected to \$SH\n"; select(STDERR); $| = 1; print STDERR "ioscalar says 'hi'\n"; close(STDERR); open(STDERR, ">&oldfh"); # restore STDERR select(STDOUT); return $data; } __DATA__ Trying ioscalar... STDERR saved. $SH created.

      I am curious to see if the following works for you or not:
      use strict; use warnings; use IO::Scalar; my $str; my $err = tie *STDERR, 'IO::Scalar', \$str; print STDERR "captured\n"; undef $err; untie *STDERR; print STDERR "not captured\n";
      UPDATE:
      whoops, this is exactly what shenme already said. My apologies.

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://291300]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (14)
As of 2015-07-31 19:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (280 votes), past polls