0

Javaからgnuplotプロセスを実行するのに問題があります。gnuplotスクリプトファイルを作成し、Javaプログラム内から実行しています。Process Builderを使用して、Runtime.getRuntime()。exec( "blah blah ...")を使用して歳差運動を構築しようとしましたが、どちらも完全に機能する機能はありません。面白いのは、ランタイムを使用してプロセスをほぼ完全に機能させることです。ただし、gnuplotで作成している画像ファイルが、名前にスペースが含まれていないディレクトリに保存されていない限りです。ただし、ProcessBuilderはまったく機能せず、「CreateProcess error = 2、システムは指定されたファイルを見つけることができません」というエラーが表示されます。

このことを理解するのに時間がかかりすぎたので、助けていただければ幸いです。

私が使用するコードはここにあります:

File script = new File("Demo.plt");    //Script file that outputs to a PNG file

//This works as long as the script file doesn't output to a png with a space in it's filepath
Process aProcess = Runtime.getRuntime().exec("gnuplot " + script.toString());
Thread.currentThread().sleep(1000);
aProcess.waitFor();

//This doesn't work at all
ProcessBuilder builder = new ProcessBuilder("gnuplot " + script.toString());
builder.redirectErrorStream(true);
Process process = builder.start();

また、出力行のスペースに関係なく、Javaの外部で実行するとスクリプトが機能することを私は知っています。'\'(スペースのエスケープ文字)を使用してみましたが、それも機能しません。実際、私が使用するコードは次のとおりです。

String graphName = "DemoGraph";
//Isolate the FilePath
String path = script.getPath();
path = path.replace(script.getName(),"");
path = path.replace(File.separator, "\\\\"); //Gets around any parsing errors in filepaths on Windows
path = path.replace(" ", "\\ ");   //Should get around parsing errors with spaces in gnuplot, but it seems to be irrelevant.

scriptFileWriter.write("set output \"" + path + graphName + ".png\"\r\n");

スクリプトはWindowsコマンドラインとgnuplotコマンドラインから実行され、frunはダブルクリックして実行されるため、Javaの問題になるはずです。

4

1 に答える 1

1

I forgot to put quotes around the file name. It was a STUPID error.

于 2012-06-01T21:14:35.980 に答える