Hallo.
Ich möchte aus meinem Java-Programm heraus gnuplot dazu veranlassen eine Datei mit Befehlen zu öffnen und auszuführen. Befehle wie "ls" kann ich Problemlos ausführen, nur mit gnuplot klappt es nicht. Es kommt auch keine Fehlermeldung (die müsste ich sehen können; zum test habe ich auch eine fehlerhafte gnuplot-Datei verwendet).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | public void runGnuplot() { String command = "gnuplot '"+this.filePlotfile.getAbsolutePath()+"' "; command = "ls -al"; // funktioniert! command = "pwd"; // ergibt das korrekte Arbeitsverzeichnis (mit der gnuplot-Datei) command = "which gnuplot"; // ergibt: /opt/local/bin/gnuplot command = "/opt/local/bin/gnuplot '"+this.filePlotfile.getAbsolutePath()+"'"; command = "/opt/local/bin/gnuplot 'test.plot'"; System.out.println("Try to run GnuPlot for the file: "+ this.filePlotfile.getAbsolutePath()); System.out.println("Command used: "+ command); Runtime r = Runtime.getRuntime(); Process p; BufferedReader read; try { p = r.exec(command); read = new BufferedReader(new InputStreamReader(p.getInputStream())); String zeile; while((zeile = read.readLine())!=null){ System.err.println("GnuPlot execution ERROR: " + zeile); } } catch (IOException e) { System.err.println("ERROR while executing gnuplot command."); e.printStackTrace(); } System.out.println("Done"); } |
Hat jemand eine erklärung dafür?
Wenn ich den Befehl der für die Ausführungs erzeugt wird, direkt ins Terminal eingebe, klappt alles ohne Probleme.
Grüße und Danke.