我试图使用processbuilder从java执行一些VBScript。我正在运行我的java代码作为tomcat servlet的一部分。如果我从命令行运行相同的命令 - 它运行正常。尝试过打开权限(每个人=完整的烫发)
Java Code(摘录):
ProcessBuilder pb = new ProcessBuilder("cscript", "C:\\Users\\Public\\Documents\\office2pdf.vbs", "C:\\Users\\Public\\Documents\\temp\\22.doc");
Process pr = pb.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
String line = null;
StringBuilder sb = new StringBuilder("");
while ( (line = reader.readLine()) != null) {
sb.append(line);
}
int i = pr.waitFor() ;
getServletContext().log("pb response="+i+", er="+sb.toString());
VBScript(摘录):
Sub SaveWordAsPDF(p_strFilePath)
'Save Word file as a PDF
'Initialise
Dim objWord, objDocument
Set objWord = CreateObject("Word.Application")
Wscript.Echo p_strFilePath
'Open the file
Set objDocument = objWord.Documents.Open(p_strFilePath)
'Save the PDF
objDocument.SaveAs PathOfPDF(p_strFilePath), WORD_PDF
'Close the file and exit the application
objDocument.Close FALSE
objWord.Quit
End Sub
我已经追踪到远远看到vbscript正在加载;实际上,'Wscript.Echo p_strFilePath'这一行确实打印了doc这个单词的正确路径。根据从java返回的错误流,来自vbscript的违规行是:'set objDocument = objWord.Documents.Open(p_strFilePath)',其说法是:
Microsoft VBScript运行时错误:所需对象:'objWord.Documents.Open(...)'
不确定这是否只是从不完整的路径触发;看了很多帖子 - 找不到任何与我的情况完全匹配的帖子。非常感谢任何建议!