Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Okay I have cleaned it up a little bit

by johngg (Abbot)
on Feb 15, 2007 at 19:55 UTC ( #600285=note: print w/replies, xml ) Need Help??

in reply to Okay I have cleaned it up a little bit

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.



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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://600285]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2018-05-25 19:22 GMT
Find Nodes?
    Voting Booth?