我试过寻找答案,但没有人为我工作。
我试图从我的Mac上的Java应用程序在终端中运行pdflatex。
在终端中,如果我键入:
open -a FireFox http://www.yahoo.co.uk它会在我的FireFox浏览器中打开yahoo.co.uk
要么
pdflatex x.tex它处理文件
在我的Java代码中,我键入:
open -a FireFox http://www.yahoo.co.uk'它会在我的FireFox浏览器中打开yahoo.co.uk
要么
pdflatex x.tex我收到一个错误。
代码如下:
public static void main(String args[]) {
String s = null;
try {
Process p = Runtime.getRuntime().exec("pdflatex x.tex");
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
// read the output from the command
System.out.println("Here is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
// read any errors from the attempted command
System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}
System.exit(0);
} catch (Exception e) {
System.out.println("exception happened - here's what I know: ");
e.printStackTrace();
System.exit(-1);
}
}这是错误:
exception happened - here's what I know:
java.io.IOException: Cannot run program "pdflatex": error=2, No such file or directory at
java.lang.ProcessBuilder.start(ProcessBuilder.java:460) at
java.lang.Runtime.exec(Runtime.java:593) at
java.lang.Runtime.exec(Runtime.java:431) at
java.lang.Runtime.exec(Runtime.java:328) at
test.JavaRunCommand.main(JavaRunCommand.java:28)
Caused by: java.io.IOException: error=2, No such file or directory at
java.lang.UNIXProcess.forkAndExec(Native Method) at
java.lang.UNIXProcess.(UNIXProcess.java:53) at
java.lang.ProcessImpl.start(ProcessImpl.java:91) at
java.lang.ProcessBuilder.start(ProcessBuilder.java:453) ... 4 more
我试过JProc,因为它是来自另一篇文章的解决方案,但它仍然有一个类似的错误:
Exception in thread "main" org.buildobjects.process.StartupException:
Could not startup process 'pdflatex x.tex '.
at org.buildobjects.process.Proc.(Proc.java:46) at
org.buildobjects.process.ProcBuilder.run(ProcBuilder.java:111) at
test.JavaRunCommand.main(JavaRunCommand.java:20)
Caused by: java.io.IOException:
Cannot run program "pdflatex x.tex": error=2, No such file or directory at
java.lang.ProcessBuilder.start(ProcessBuilder.java:460) at
java.lang.Runtime.exec(Runtime.java:593) at
org.buildobjects.process.Proc.(Proc.java:43) ... 2 more
Caused by: java.io.IOException: error=2, No such file or directory at
java.lang.UNIXProcess.forkAndExec(Native Method) at
java.lang.UNIXProcess.(UNIXProcess.java:53) at
java.lang.ProcessImpl.start(ProcessImpl.java:91) at
java.lang.ProcessBuilder.start(ProcessBuilder.java:453) ... 4 more