Javaアプリケーションからプロセスを実行しようとしています。コンソールからこのプロセスを実行すると、正しく機能しますが、getRuntime()。exec()を実行すると、開始されますが終了しません。例外も終了値もありません。私が実行しようとしているプロセスは、PDFファイルをPostScriptに変換するアプリであるpdftops.exeです。小さなファイルを変換しようとすると(Javaから実行)、問題なく動作します。問題は、より長い時間(20〜60秒)かかる可能性のある大きなPDFの変換です。実行時間が長すぎることが問題だと思います。プログラムを呼び出すコードは次のとおりです(コマンドラインが簡略化され、input.pdfとoutput.psがホームディレクトリ内のフォルダーに配置され、pdftops.exeがデスクトップに配置されます)。
String comando = "pdftops.exe input.pdf output.ps";
System.out.println("Executing "+comando);
try {
Process pr = Runtime.getRuntime().exec(comando);
pr.waitFor();
System.out.println("Finished");
}
catch (IOException ex){
ex.printStackTrace();
}
catch(InterruptedException ex){
ex.printStackTrace();
}
編集:プロセスのErrorStreamを読み取ると、問題が解決します。
try {
System.out.println(comando);
Process process = Runtime.getRuntime().exec(comando);
String line;
InputStream stderr = process.getErrorStream ();
BufferedReader reader = new BufferedReader (new InputStreamReader(stderr));
line = reader.readLine();
while (line != null && ! line.trim().equals("--EOF--")) {
System.out.println ("Stdout: " + line);
line = reader.readLine();
}
}
catch (IOException ex){
ex.printStackTrace();
}