procmail
[Top] [All Lists]

Re: Checking the exitcode of a program

2001-01-21 15:57:37
Jaime wrote,

| Hi. Is it possible to do different things depending on the exitcode of a 
| program? like, if it's 0 do something, if 1 something else, and if 100 
| another?

Yes.  I've never tried referring to $? in a procmail rcfile, but I believe it
means the same thing as it does in sh [the procmailrc(5) man page says that
procmail understands it but doesn't say what it means to procmail].  So if
you run the program as an action, you should be able to refer to $?, like
this:

  :0c # include `i' if the program does not read in the message
  * conditions limiting which messages you run the program on
  | command -opts args

  EXITSTATUS = $?

if you run it as a condition, it's easier (in my opinion):

  :0
  * other conditions limiting which messages you test this on
  * 1^1 ! ? command -opts args
  { } # the score will be the exit code of the command

  EXITSTATUS = $=

The variable in which you store the exitcode should _N_O_T_ be named EXITCODE
because that would make procmail exit with that code.

You can then examine the variable as text in a later recipe,

  * EXITSTATUS ?? regexp

or use it as a number by including it in the score of a later recipe:

 * $ $EXITSTATUS^0

For example, if it can be 0, 1, or 100,

  :0
  * 1^1 ! ? command
  {
   # procmail goes into braces if exit status was positive
   EXITSTATUS = $=

   :0 flags
   * EXITSTATUS ?? 100
   action_if_100

   :0E other flags
   * EXITSTATUS ?? ^^1^^
   action_if_1

   :0E
   catchall_for_other_nonzero_values
  }
  :0E # procmail goes here if exit status was 0
  action_on_success

| It has to do with the vpopmail and quotas problem i mentioned in an earlier 
| posting, the program is the vpopmail delivery agent, it returns 0 on success, 
| and 100 on failure, outputting to stdout a better description, so i can make 
| a little wrapper script that returns something depending on the case, but how 
| can i process the response from procmail? i can exit with an exitcode 
| depending on each case, but how can procmail process that?

Well, then you don't even need the exact exit code; all you need to know is
whether it's zero or not (which is different from what you said at first,
that exiting 1 and exiting 100 required different reactions).

  :0
  * ? vpopmail -opts args
  action_on_success_of_vpopmail
   :0E
   action_on_failure_of_vpopmail

except that you want to save the stdout.  So let's try this:

 :0w
 VPOPMAILOUTPUT=| vpopmail -opts args

 EXITSTATUS = $?

After that point I don't know what the code should read, as I don't know what
you want to do with the stdout from vpopmail.

_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>