I am trying to plot a sine graph using GNUPLOT in PHP, but when I use exec to plot the graph I get this error:
Warning: exec() [function.exec]: Cannot execute a blank command in
/Library/WebServer/Documents/serverSide2.php on line 8
here is my code:
exec(`echo "set term png;set xrange[-2*pi:2*pi]; set output 'output.png'; plot sin(x)" | gnuplot`);
I used passthru() also but got the same error:
Warning: passthru() [function.passthru]: Cannot execute a blank command in /Library/WebServer/Documents/serverSide2.php on line 8
However I used the terminal to check whether the code is working or not, so I entered this code:
echo "set term png;set xrange[-2*pi:2*pi]; set output 'output.png'; plot sin(x)" | gnuplot
and it worked properly and gave me the plot.
any I idea what should I do?
You are using the wrong syntax.
Either use
execand write the command line as a string literal:or use backticks and do not involve
execat all:With the code you already have, the backticks cause the command to be executed and its output to be passed to
exec. Since this command line produces no output,execthen complains that it cannot execute a blank command.