I am using Perl to write a CGI program that pipes input into Gnuplot as per here:
how to call a gnuplot script from perl
First, I test all of my gnuplot plotting routines by writing a .gnu file and executing it with gnuplot in the bash terminal. I have tried many different gnuplot terminals with corresponding output formats ("set terminal ..., set output...") and this always works.
Second, after performing this first test, I try to pipe the same 'string' (roughly speaking) from the .gnu file to gnuplot from the perl script. I have checked many times to make sure that the string has properly escaped characters. This works for the epslatex terminal, but it does not work for the png, gif, pdf, jpeg, cairolatex, or pdfcairo terminals although all these terminal types worked in my first test case. What I mean by "does not work" is that using these terminals in the Perl CGI produces a file of the output name, but it has a 0kB size.
I suspected there might be something wrong with flushing the pipe, similar to:
Why doesn't my parent process see the child's output until it exits?
But adding a newline character at the end of the string piped to gnuplot and then turning on autoflush ($|=1) did not fix the problem.
I am pretty stumped. Any idea what might be going on?
Edit: Here is example code:
Does work:
open my $GP, '|-', 'gnuplot';
my $GPoutput = "set xrange [-5:5]
set terminal epslatex
set output \"graph1.tex\
plot sin(x)";
$|=1;
print $GP "$GPoutput";
Does not work:
open my $GP, '|-', 'gnuplot';
my $GPoutput = "set xrange [-5:5]
set terminal cairolatex
set output \"graph1.tex\
plot sin(x)";
$|=1;
print $GP "$GPoutput";
Although if I put the string of $GPoutput into a .gnu file and execute gnuplot from the command line it does work, and running "set terminal" on gnuplot shows that cairolatex is a valid terminal.