简体   繁体   中英

Procmail recipe, pipe to Java stdin

I'm trying to run some custom parsing on incoming mail using procmail, and would like to call a java program to read in the headers and body of the message using the |pipe to stdin. There are plenty of examples of having your mail filtered using perl, and python, but none using java. As a starting example, my procmail recipe:

:0 hbfW
|"/usr/bin/java -cp /root/parser HelloWorldApp"

And my java app just echo's stdin:

import java.io.*;
public class HelloWorldApp {
 public static void main(String[] args) {
 InputStreamReader isReader = new InputStreamReader(System.in);
BufferedReader bufReader = new BufferedReader(isReader);
while(true){
    try {
        String inputStr = null;
        if((inputStr=bufReader.readLine()) != null) {
            System.out.println(inputStr);
        }
        else {
            break;
        }
    }
    catch (Exception e) {
       break;
    }
  }
 }
}

procmail log:

procmail: Executing "/usr/bin/java -cp /root/parser HelloWorldApp"
/bin/sh: /usr/bin/java HelloWorldApp: No such file or directory
procmail: Error while writing to "/usr/bin/java HelloWorldApp"
procmail: Rescue of unfiltered data succeeded

1) Am I creating the right recipie to pipe the data to java? 2) Since I still want procmail to handle delivery, my recipe using the (f) flag. But how to I have the result created from my java program sent back to procmail? stdout?

remove the quotation marks around "/usr/bin/java -cp /root/parser HelloWorldApp".

source: http://www.linfo.org/pipe.html

The "filter" flag on your recipe specifies that the pipeline will read a message on standard input and write back a (possibly not altered) message on standard output, which will replace the original message.

As Jake223 already replied, the quotation marks around the command are incorrect, and should be removed. The error message doesn't really look like it corresponds to that particular error, though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM