私は答えを探してみましたが、私のために働いているものはありません。MacでJavaでコマンド 'pdflatex'を実行する方法
私のMacのJavaアプリケーションからターミナルでpdflatexを実行しようとしています。ターミナルで
私が入力した場合:
open -a FireFox http://www.yahoo.co.uk
をそれは私にはファイル
を処理し、私のFirefoxブラウザ
または
pdflatex x.tex
でyahoo.co.ukを開きますJavaコードIタイプ:
open -a FireFox http://www.yahoo.co.uk'
それは私がエラーを取得する私のFirefoxブラウザ
または
pdflatex x.tex
でyahoo.co.ukを開きます。ここで
はコードです:
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
'which pdflatex'をコマンドラインで表示し、Javaコードの' pdflatex'をそのフルネームで置き換えてみてください。 – alf
ありがとう@alf!出来た!しかし、今私は生成されたPDFファイルを開きたい。 pdflatexを呼び出して、結果として得られるpdfファイルを一度に開くにはどうすればよいですか? –
私はそれをやりました - バッチファイルを書いて実行しました。ご協力いただきありがとうございます! :) –