Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
ikegami has advised the use of MIME::Lite but note that it is not a core part of Perl and would need to be loaded by your local friendly sysadm. (or your good self if you fill that role).

blazar has given a lot of good advice. I think it might be useful to expand on the use of system and how you would check that the command you ran succeeded or not. When you run a command it finishes with an exit status and, by convention, success is signified by an exit status of zero. When running from the shell in a terminal window of some sort you can check the exit status by examining a shell built-in variable, $? on Bourne and Korn shells (/bin/sh and /bin/ksh) or $status if using the C-shell (/bin/csh). You can do echo $SHELL to find out which you are using. Using the Korn shell you can see what happens when I do an ls on existent and non-existent files

$ touch goodfile $ ls goodfile goodfile $ echo $? 0 $ ls badfile badfile: No such file or directory $ echo $? 2 $

If I do the same thing using system in a Perl script (in this case actually typed in at the command line) I can still examine the exit status, this time using a Perl built-in variable also called $?. This time, however, there is more information available; see the system man page for the gory details but the bottom line is you have to shift $? right 8 bits to get the exit status. Like this

$ perl -le ' > @cmd = qw{ls goodfile}; > system @cmd; > exit unless $?; > print $?, q{ - }, $? >> 8;' goodfile $ perl -le ' > @cmd = qw{ls badfile}; > system @cmd; > exit unless $?; > print $?, q{ - }, $? >> 8;' badfile: No such file or directory 512 - 2 $

So, the point of the above is that it is good practice to check that your command actually ran rather than trusting to fate.

If you are wanting to capture the output of your bpdbjobs command in order to send it in an email you should be using backticks or qx{ ...}, ($output = `command`; or $output = qx{command};) instead of system. There are references on the system manual page to follow if that is what you want.

I hope you find this helpful.

Cheers,

JohnGG

Update: Corrected cut'n'paste error in the last paragraph.


In reply to Re: Okay I have cleaned it up a little bit by johngg
in thread Okay I have cleaned it up a little bit by Kevin_Raymer

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (7)
    As of 2014-09-02 06:46 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite cookbook is:










      Results (20 votes), past polls