pdf 中的java运行,如何在Mac上的Java中运行命令'pdflatex'

我试过寻找答案,但没有人为我工作。

我试图从我的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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值