On Monday, June 9, 2003, at 02:45 am, drieux wrote:On Sunday, Jun 8, 2003, at 08:58 US/Pacific, Robin wrote:Yes, but that's the point. It returns 0, even though it clearly failed to send the mail.On Thursday, June 5, 2003, at 03:36 am, Dan Mills wrote:[..]It's unfortunate that mail exits with 0, however. .........It isn't mail's fault, though. sendmail returns with 0 as well.it's a UNIX C-ism which return 0 instead - historically any other return value would be an error codemail, mailx, et al 'ran successfully' - and hence should exit with '0' - because they ran successfully.
the point being that certain Unix command line tools don't use a boolean ('1' = yes, '0'= no) as a way of codifying success for reasons which are connected to programming C on Unix, the logic of which can still be seen in certain man pages.
So the real question is what success does that '0' represent?
(lifted from a SunOS man page for mail at http://bama.ua.edu/cgi-bin/man-cgi?mail+1):
EXIT STATUS
The following exit values are returned:
0 Successful completion when the user had mail.
1 The user had no mail or an initialization error occurred.
You got mail apprently - did you check? :-) In all fairness the OSX manpages don't talk about return values, I suppose they assume you wouldn't be running mail except in interactive mode. A fair assumption - there are ways to forward/send mail which don't use either mail or sendmail, (one of them is Net::SMTP).
But I feel the poster's real question is about why the example from the official bible for perl learners doesn't do what the book says it should - before OSX, Unix systems always had a SMPT/POP mail daemon built into the system, which as surely as night follows day would be active and fully functioning. In OSX the daemon is not configured by default and requires considerable tweaking to be kept running across software updates due to the Apple installers resetting disk permissions. In short the Learning Perl example doesn't even consider the fact that there might not be a working mail daemon, which is unthinkable on all flavours of Unix except OSX.
If you have a working mail daemon then:
*in mail.app you could set the SMTP and POP servers to localhost (127.0.0.1)
*other people would be able to send mail through your computer onto the internet
and checking in the terminal checking for a process called sendmail would get you this:
[blue:~] robin% ps -aux | grep sendmail
smmsp 1381 0.0 0.3 2204 924 p1 S+ 12:33PM 0:01.73 sendmail
robin 1387 0.0 0.1 1416 312 std S+ 12:34PM 0:00.01 grep sendmail
otherwise you'll only see the grep command looking for a process called sendmail:
robin% ps -aux | grep sendmail
robin 1389 0.0 0.0 1116 4 std R+ 12:35PM 0:00.00 grep sendmail
you can of course put this into a perl script that checks if sendmail is running:
#!/usr/bin/perl -w
#=========== declare includes =============
use strict; use diagnostics-verbose;
#========== declare variables =============
my($test);
#============= script body ================ $test=`ps -aux | grep sendmail`; print "Sendmail running\n" if $test=~/^smmsp/; print "Sendmail not running\n" if $test!~/^smmsp/;
hth
Robin