简体   繁体   中英

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, ie why the 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:

  1. 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.

  2. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM