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

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Did someone say "trap"? Test::Trap to the rescue! :)

The error message you want is printed on STDOUT on my machine. I was expecting STDERR. Other errors may come from the Perl code, so we want the $@ as well. My very own Test::Trap can give you all! :)

The example below, based on your code, makes use of the :output(systemsafe) pseudo layer, new in version 0.1.0. Older versions of Test::Trap may use :flow:stderr(systemsafe):stdout(systemsafe) to much the same effect.

#!/usr/bin/perl -w use Test::Trap qw/ :output(systemsafe) /; use MIME::Lite; # send mail attachments use Sys::Hostname; # Used to insert hostname in emails use Cwd; # Get current full dir for error msgs use strict; # Enforce declarations my ( $hostname, # name of this box for sending $prog_full_name, # prog path + name $contact_email, # contact email address $msg, # msg object $sender, # sender of email $subject, # subject line in email $body_text # actual email msg text ); # Get hostname anyway we can using Sys::Hostname; # tries syscall(SYS_gethostname), `hostname`, `uname -n` $hostname = Sys::Hostname::hostname(); # Get program full path name $prog_full_name = cwd()."/${0}"; # Set the fields required by Mailer... $contact_email = ''; $sender = "$prog_full_name"; $subject = "$prog_full_name: Asset Mgr Report"; $body_text = "This is an automated message:\n\n"; # ... and send it # Header $msg = MIME::Lite->new( From => $sender, To => $contact_email, Subject => $subject, Type =>'multipart/mixed' ); # Body Content $msg->attach( Type => 'TEXT', Data => $body_text ); # Attachment $msg->attach( Type => 'text/plain', Path => "/home/chrism/t.cvs", Filename => "t.csv", Disposition => 'attachment' ); # Send trap { $msg->send or print "Error: $@\n" }; $_ and print "Error: $_\n" for $trap->die, $trap->stdout, $trap->s +tderr;

print "Just another Perl ${\(trickster and hacker)},"
The Sidhekin proves Sidhe did it!

In reply to Re: Trap the error msg from Mime::Lite by Sidhekin
in thread Trap the error msg from Mime::Lite by chrism01

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (2)
    As of 2018-02-20 02:51 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (267 votes). Check out past polls.