Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Re: Best Way to Redirect STDERR to a Scalar

by Mr. Muskrat (Canon)
on Sep 14, 2003 at 01:09 UTC ( #291326=note: print w/replies, xml ) Need Help??

in reply to Re: Best Way to Redirect STDERR to a Scalar
in thread Best Way to Redirect STDERR to a Scalar

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.

Replies are listed 'Best First'.
3Re: Best Way to Redirect STDERR to a Scalar
by jeffa (Bishop) on Sep 14, 2003 at 08:10 UTC
    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";
    whoops, this is exactly what shenme already said. My apologies.


    (the triplet paradiddle with high-hat)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://291326]
QM waves to the peanut gallery, and wishes he were writing Perl today.

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2017-06-29 09:58 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (657 votes). Check out past polls.