我想知道如何在我的php脚本中使用exec命令来调用Gnuplot。
首先,我将给出一些背景背景:
我已经写了几个php文件,它们从数据库中抓取数据,并将记录的值放入文本文件中,以便gnuplot可以读取它们。在此基础上,我有了第二个php文件,它生成了一个gnuplot脚本,该脚本具有用于创建图形的适当指针。
我可以手动转到c:/gnuplot/gnuplot/binary/gnuplot.exe graph.txt并手动生成图形,但我不知道如何自动生成它。
Linux和Windows的建议都会很有帮助!我正在编写它并在windows上测试它,但是一旦它被修复,它就会被送到我们的Linux服务器上。
谢谢!
发布于 2011-06-29 01:07:19
要在Linux机器上执行gnuplot,可以使用php中的exec()函数。我不确定你到底想对输出做什么,但是exec绝对可以运行这个程序。
发布于 2012-06-09 20:34:05
这是我用来让PHP和gnuplot对话的一些非常旧的代码,很久以前它甚至不支持PNG输出,所以使用了。这还没有在Windows上测试过:
// Assuming data has been written to $data_file...
$image_file = tempnam("/tmp","gnuplotout");
$gplot_start = date("y/m/d", $start_date);
$gplot_finish = date("y/m/d", $finish_date);
$gnuplot_cmds = <<< GNUPLOTCMDS
set term pbm color small
set output "$image_file"
set size 1, 1
set title "Title"
set xlabel "Date"
set ylabel "EUR"
set xdata time
set timefmt "%y/%m/%d"
set xrange ["$gplot_start":"$gplot_finish"]
set format x "%d/%m"
set nokey
plot "$data_file" using 1:2 with lines
GNUPLOTCMDS;
$gnuplot_cmds .= "\n";
// Start gnuplot
if(!($pgp = popen("/usr/bin/gnuplot", "w"))){
# TODO Handle error
exit;
}
fputs($pgp, $gnuplot_cmds);
pclose($pgp);
header("Content-Type: image/png");
passthru("/usr/bin/pnmtopng $image_file");
// Clean up and exit
unlink($data_file);
unlink($image_file);
exit;https://stackoverflow.com/questions/6510263
复制相似问题