Just use local() within a block as tybalt89 suggested to save and then restore the filehandles.
Note: Using Mail::sendMail as described heresub SendMemberMail { my ($subject,$from,$to,$port,$cc,$bcc,$heading,$body,$closing,$signi +ture,$auth) = @_; warn("In SendMemberMail before redirect of STDERR & STDOUT"); $Mail::sendMail::mailcfg{'debug'} = 6; $Mail::sendMail::mailcfg{'port'} = $port; my $message = "$heading\n\n$body\n\n$closing\n\n$signiture\n"; my %mail = ( To => $to, From => $from, Cc => $cc, Bcc => $bcc, Subject => $subject, Message => $message, ); if ($auth == 1) { $mail{'Auth'} = { user => '', password => '', method => 'PLAIN LOGIN', required => 1 }; }; my $logfile = '/home/abcus/public_html/httpsdocs/cgi-bin/lib/perl/Ma +il/mail.log'; open my $fh, '>>', $logfile or die "Error opening $logfile : $!"; SEND: { local *STDOUT = $fh; local *STDERR = $fh; if ( SendMail(%mail) ) { print $Mail::sendMail::log; } else { print $Mail::sendMail::error; } } close $fh; select STDOUT; # Test original handles print "stdout 2\n"; warn("warn stderr 2\n"); return 1; }
In reply to Re^3: STDERR Restore after redirect
by poj
in thread STDERR Restore after redirect
by tultalk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |