tultalk has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks:
In code block below, the saved fh's are not restored and a print command executed later in a different module prints to my log. If I close the handle it produces a print to closed handle error.
The email is completed and sent and the logging shows continued posting to the $fh/log after returning to the caller and the callers caller.
How do I restore the handles and close $fh?
Looks to me like some examples I found in "The Monastery"
Thanks
sub SendMemberMail { my ($subject,$from,$to,$port,$cc,$bcc,$heading,$body,$closing,$signi +ture,$auth) = @_; # Open log for recording during execution of SendMail my $sendMail_logfile = '/home/abcus/public_html/httpsdocs/cgi-bin/li +b/perl/Mail/mail.log'; open(my $fh, "+<", "$sendMail_logfile") or die "Opening: $!"; my $previous_STDOUT_fh = select(STDOUT); my $previous_STDERR_fh = select(STDERR); #Redirect STDERR & STDOUT to $fh for this sub *STDOUT = $fh; *STDERR = $fh; my $message = ($heading . "\n" . "\n" . $body . "\n" . "\n" . $closing . "\n" . "\n" . $signiture . "\n" ); if ($auth == 1) { $auth = {user=>'webmaster@abc.us', password=>'wm@xxxx', method=>'P +LAIN LOGIN', REQUIRED=>1} } elsif ($auth == 0) { $auth = ""; } my %mail = ( To => $to, From => $from, Cc => $cc, Bcc => $bcc, Auth => $auth, Port => $port, Subject => $subject, Message => $message, debug => 18 ); SendMail(%mail) or die $Mail::sendMail::error; $log .= "Sending eMail Succeded\n"; #Print the data from the $log. print $fh $log; #restore the standard handles select($previous_STDOUT_fh); select($previous_STDERR_fh); close($fh); return 1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: STDERR Restore after redirect
by choroba (Cardinal) on Apr 26, 2018 at 22:12 UTC | |
by tultalk (Monk) on Apr 26, 2018 at 22:59 UTC | |
by tultalk (Monk) on Apr 27, 2018 at 00:13 UTC | |
by choroba (Cardinal) on Apr 27, 2018 at 08:36 UTC | |
by poj (Abbot) on Apr 27, 2018 at 19:28 UTC | |
by huck (Prior) on Apr 28, 2018 at 22:45 UTC | |
|
Re: STDERR Restore after redirect
by eyepopslikeamosquito (Archbishop) on Apr 28, 2018 at 05:23 UTC | |
|
Re: STDERR Restore after redirect
by tybalt89 (Monsignor) on Apr 27, 2018 at 00:42 UTC | |
by tultalk (Monk) on Apr 27, 2018 at 03:54 UTC | |
by Anonymous Monk on Apr 27, 2018 at 13:02 UTC | |
|
Re: STDERR Restore after redirect
by djerius (Beadle) on Apr 27, 2018 at 17:19 UTC | |
by tultalk (Monk) on Apr 27, 2018 at 19:29 UTC | |
by poj (Abbot) on Apr 27, 2018 at 19:50 UTC | |
by tultalk (Monk) on Apr 28, 2018 at 02:19 UTC | |
by AnomalousMonk (Archbishop) on Apr 28, 2018 at 03:23 UTC | |
| |
by tultalk (Monk) on Apr 28, 2018 at 16:23 UTC | |
by AnomalousMonk (Archbishop) on Apr 28, 2018 at 16:57 UTC | |
| |
by poj (Abbot) on Apr 28, 2018 at 17:06 UTC | |
| |
|
Re: STDERR Restore after redirect
by Anonymous Monk on Apr 30, 2018 at 02:07 UTC |