creating a pipe and writing to gnuplot terminal from c++
I am trying to call the gnuplot from c++. I am using wgnuplot for Windows and VS2005 c++.
The following statement works because it opens the gnuplot terminal
FILE *p = _popen("wgnuplot -persist","w");
But I cannot write anything there. My terminal is still blank even after running the following code.
fprintf(p, "set terminal x11 enhanced\n"); //set appropriate output terminal for the plot
fprintf(p, "set xlabel 'N'\n");//set xlabel
fprintf(p, "set ylabel 'error'\n");//set ylabel
Could you please tell me what might be the problem, i.e. why th开发者_StackOverflow中文版e terminal is blank and fprintf() doesn't seem to work?
Thanks,
Boris
Check that FILE pointer is not NULL:
if(!p)
// _popen() has failed...
I do not know if that helps you, but this is my approach of executing gnuplot from my C programs:
I create a template file (usually I do not delete it, so that it is easier to troubleshoot), where all the gnuplot commands are are scripted in.
I run gnuplot with
system("gnuplot <TemplateFile>")
If you are only interested in creating a plot, that his would do the job. If you are explicitly interested in the approach you described above then just disregard this posting ;)
Cherio Woltan
精彩评论