You can use open() and get the return value from $?. If you check $? after the program closes, that should contain the return value. Well, kinda:
from the entry for $? on the perlman:perlvar page:
The status returned by the last pipe close, backtick (``) command, or system() operator. Note
that this is the status word returned by the wait() system call (or else is made up to look like it).
Thus, the exit value of the subprocess is actually ( $? >> 8), and $? & 127 gives which signal, if
any, the process died from, and $? & 128 reports whether there was a core dump. (Mnemonic:
similar to sh and ksh.)
Check out perlfunc:open and perlman:perlipc for examples.
Since you're writing to the pipe, then you'll probably want
to install a handler for SIGPIPE signals, as well.
So, your code could be:
$SIG{PIPE} = sub { die "Your pipe handler here! $!"; };
$prog = "/var/qmail/bin/qmail-remote";
$msg = "this is the email message";
open (OUT, "|$prog") or die "Couldn't open Qmail: $!; stopped";
print OUT $msg;
close(OUT) or die "Couldn't close Qmail: $! $?; stopped";
my $return_code = $? >> 8;
print STDOUT "My return code was $return_code.\n";
stephen
| [reply] [d/l] |
Yup. A coupla points
Always test the result of a 'close' if the 'open' runs a program with the pipe character. Otherwise you have no idea if the program ran successfully.
Why hard-code you script to run on a box with one particular email system installed. There is a perfectly fine Net::SMTP module out there which is dead easy to use.
Just dive straight into your local SMTP port and acheive one-ness with the world.
(OK, well, so you might want to run on a box which is send-only for SMTP, but hey) | [reply] |