Hi. I will take a look

As it now stands, code below works except for one quirk.

sub SendMemberMail { my ($subject,$from,$to,$port,$cc,$bcc,$heading,$body,$closing,$signi +ture,$auth) = @_; warn("In SendMemberMail before redirect of STDERR & STDOUT"); # 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: $!"; #Redirect STDERR & STDOUT to $fh for this sub open my $oldSTDOUT, ">&STDOUT"; open OLDERR, ">&",\*STDERR; open (STDERR, ">>&=", $fh) || die "can't redirect STDERR"; open (STDOUT, ">>&=", $fh) || die "can't redirect STDOUT"; $fh->autoflush(1); my $message = ($heading . "\n" . "\n" . $body . "\n" . "\n" . $closing . "\n" . "\n" . $signiture . "\n" ); if ($auth == 1) { $auth = {user=>'webmaster@abc.us', password=>'xx@33333XX', method= +>'PLAIN 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 => 0 ); SendMail(%mail) or die $Mail::sendMail::error; $log .= "Sending eMail Succeded\n"; #Print the data from the $log. print $fh $log; #Test redirected handles print STDOUT "stdout 1\n"; warn("warn stderr 1\n"); close($fh); #restore the file standard handles open(STDOUT, ">&", $oldSTDOUT) or die "Can't dup \$oldout: $!"; open(STDERR, ">&OLDERR") or die "Can't dup OLDERR: $!"; #Test original handles print STDOUT "stdout 2\n"; warn("warn stderr 2\n"); return 1; }

The mail is sent. The handles are restored as evidenced by stderr2 in my regular error log file and stderr/stdout in my pre-restore log file. What is gone in the nether world is the stdout2 and the printing of the HTML form to stdout back to client.

If I don't close the handle, the form (text) is printed to the sendMail logfile.

I put warns at beginning of the sub to print the html and at the end and both appear in the error log indicating execution of that block but no form returned to client.

As I posted earlier, if I bypass the call to sendMail(), the form prints as expected.

For some reason the call to print the form is not directed to the (opened)STDOUT nor to the (closed) $fh log handle. Perhaps lost in the mist of time and sitting at the earth moon L4 LaGrange point in a huge cloud of missing documents.

I can't see anything in sendMail that could have such an effect. I shut off the debugging in sendMail which writes to stderr and no effect (except less output to the log naturally)

I guess I have to just grunt my way through this until a revelation hits me.

Scoping are weird!


In reply to Re^2: STDERR Restore after redirect by tultalk
in thread STDERR Restore after redirect by tultalk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.