从java启动的sendEmail脚本失败

时间:2017-12-15 13:51:49

标签: java

我需要使用sendEmail(http://caspian.dotconf.net/menu/Software/SendEmail/)从java发送电子邮件,但是当我尝试发送它时,我收到此错误

  

sendEmail [11869]:错误:“ - ”不是公认的选项!

但如果我在控制台中放入相同的命令(从日志中复制并粘贴命令),它可以正常工作。

这是我的代码:

String comm = "/opt/bin/sendEmail "
+ "-f \"***@***.com\" "
+ "-u \"REPORT\" "
+ "-m \"Report\" "
+ "-a \""+ pdfFileName +"\" "
+ "-s \"" host +"\" "
+ "-xu \""+ user +"\" "
+ "-xp \""+ password +"\" ";

for(String t:recipients)
    comm += "-t \""+ t  +"\" ";
log.info(comm); // It is correct! if i paste it in console it works
StringBuffer output = new StringBuffer();
Process p = Runtime.getRuntime().exec(comm);
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = reader.readLine())!= null) {
    output.append(line + "\n");
}

我在哪里做错了? 感谢

1 个答案:

答案 0 :(得分:0)

环顾四周后,我发现了这个

Using Quotes within getRuntime().exec

感谢wonderb0lt和Wietlol