Procmail 配方,管道到 Java 标准输入
我正在尝试使用 procmail 对传入邮件运行一些自定义解析,并且想调用 java 程序来使用 |pipe 到 stdin 读取消息的标头和正文。有很多使用 perl 和 python 过滤邮件的示例,但没有一个使用 java。作为一个开始的例子,我的 procmail 配方:
:0 hbfW
|"/usr/bin/java -cp /root/parser HelloWorldApp"
我的 java 应用程序只是回显标准输入:
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 日志:
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)我是否创建了正确的配方将数据通过管道传输到 java? 2) 由于我仍然希望 procmail 处理传递,因此我的配方使用 (f) 标志。但是如何将 java 程序创建的结果发送回 procmail?标准输出?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
删除“/usr/bin/java -cp /root/parser HelloWorldApp”周围的引号。
来源:http://www.linfo.org/pipe.html
remove the quotation marks around "/usr/bin/java -cp /root/parser HelloWorldApp".
source: http://www.linfo.org/pipe.html
配方上的“过滤器”标志指定管道将读取标准输入上的消息并在标准输出上写回(可能未更改的)消息,这将替换原始消息。
正如 Jake223 已经回复的那样,命令周围的引号不正确,应该删除。不过,错误消息看起来并不真正对应于该特定错误。
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.