我不确定这是否可能,特别是因为Java通过VM运行,但是我可以从Java内部调用gnuplot吗?也许我可以让Java打开一个终端并输入
gnuplot
plot ...等?
发布于 2010-07-08 00:05:51
使用gnujavaplot。
发布于 2010-07-08 00:02:34
如果可以让gnuplot从命令行或标准输入(或从文件中读取)获取所有输入,并将其输出写入文件,那么使用ProcessBuilder应该没有问题。
发布于 2011-05-11 05:19:56
这在Debian上有效:
String[] s = {"/usr/bin/gnuplot",
"-e",
"set term jpeg large size 800,600;set autoscale; set grid;set format y \"%0.f\";set output \"plot.jpg\";set xdata time;set timefmt \"%Y-%m-%d-%H:%M:%S\";set xlabel \"Dates\";set ylabel \"Data transferred (bytes)\";plot \""+x+"\" using 1:2 title \"Total:"+tot+"\" with linespoints;"
};
try {
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec(s);
InputStream stdin = proc.getErrorStream();
InputStreamReader isr = new InputStreamReader(stdin);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine()) != null)
System.err.println("gnuplot:"+line);
int exitVal = proc.waitFor();
if (exitVal != 0)
log("gnuplot Process exitValue: " + exitVal);
proc.getInputStream().close();
proc.getOutputStream().close();
proc.getErrorStream().close();
} catch (Exception e) {
System.err.println("Fail: " + e);
}https://stackoverflow.com/questions/3196563
复制相似问题