in reply to sendmail close error

What happens if you open MAIL for writing?
# now: open (MAIL, "|/usr/sbin/sendmail -t") open (MAIL, '>', "|/usr/sbin/sendmail -t")
Udate: didn't notice the | at small font size at my end. The 2 arg version will work as written. the 3 arg version would be: open (MAIL, '|-', "/usr/sbin/sendmail -t")

Weird, the open() works, but the close() fails. Does the print() work? Nobody ever checks this, but it does return a status like open or close.

Replies are listed 'Best First'.
Re^2: sendmail close error
by vit (Friar) on Jul 20, 2011 at 19:53 UTC
    I am not sure I understand what you suggest but
    print "Mail sent.\n";
    is working
      What we have is the sequence
      1. open MAIL pass
      2. print MAIL ????
      3. close MAIL fail
      step (1) succeeds, step (3) fails. The natural question is did step (2) fail or succeed? I've never seen close on a pipe fail, but it does in this case. I've never seen a print to an open pipe fail either. But, since we are into rare, weird stuff, just curious about the print to the MAIL pipe. print() returns status just like open() or close(). I admit to being stumped. This might tell us something surprising or not - but its easy to do.

      print MAIL ...... or warn "print to MAIL failed".

      Other way to code:

      #!/usr/bin/perl -w use strict; my $status = print "this is a test\n"; print "first print returned $status\n"; __END__ output: this is a test first print returned 1
        That's what I did:
        print MAIL "From: $from\n"; print MAIL "To: $to_ad\n"; print MAIL "Subject: $subject\n\n"; my $stat = print MAIL "$message"; print "Mail Status: $stat\n"; close(MAIL) || warn "Error closing mail: $!"; print "Mail sent.\n";
        I got: Mail Status: 1
        Mail sent.

        But the mail still does not reach my box and the log reports "Error closing mail:"