[Chicago-talk] Capturing a perl scripts return value in procmail?

Andy_Bach at wiwb.uscourts.gov Andy_Bach at wiwb.uscourts.gov
Fri Dec 24 08:38:05 PST 2010


>From this:
http://partmaps.org/era/procmail/quickref.html
Test exit code of external program
* ? shell command (pipeline)
The program gets the current processed message as its standard input (but 
is of course free to ignore it); the condition is successful if the 
program returns a zero exit code. If the command is a pipeline with 
several commands in it, the exit code is whatever the last program in the 
pipeline returns (at least on systems worthy of the Unix name).
Messages printed to standard error by the pipeline are displayed in the 
log.

...
Variables
Curiously, even those special pseudovariables which are primarily useful 
for their associated side effects (LOG, SHIFT, etc) can be referenced, so 
you can see what the last value you assigned to them was. This is only 
marginally useful for most of us, but comes as a pleasant surprise in 
situations where this is actually useful.

and the return value is in:
The exit code of a program called up by Procmail is in $?

If you want more, perhaps, this FAQ suggests:
http://partmaps.org/era/procmail/mini-faq.html
More-complicated conditions can also be exit codes of other shell scripts 
or programs, or tests against the full body of the message, or against 
Procmail variables (Procmail's variables are also exported to the 
environment of subprocesses, so they are essentially environment 
variables. There are details about this later in this FAQ.)

You can put them in %ENV and have procmail ref them as $<varname>
In the following example, we are grabbing the contents of the Subject:
 header into the variable SUBJECT, and then pass that in as the -s option 
of our-script.
                 SUBJECT=`formail -zxSubject:`
                 :0w:
                 | our-script -s "$SUBJECT" >>output


----------------------
Andy Bach
Systems Mangler
Internet: andy_bach at wiwb.uscourts.gov
Voice: (608) 261-5738; 
Cell: (608) 658-1890

"A witty saying proves nothing."
  --Voltaire
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20101224/14a6d506/attachment.html>


More information about the Chicago-talk mailing list