简体   繁体   English

创建管道并从C ++写入gnuplot终端

[英]creating a pipe and writing to gnuplot terminal from c++

I am trying to call the gnuplot from c++. 我正在尝试从C ++调用gnuplot。 I am using wgnuplot for Windows and VS2005 c++. 我正在Windows和VS2005 c ++中使用wgnuplot。

The following statement works because it opens the gnuplot terminal 以下语句有效,因为它打开了gnuplot终端

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? 您能否告诉我可能是什么问题,即为什么终端为空白并且fprintf()似乎不起作用?

Thanks, 谢谢,

Boris 鲍里斯

Check that FILE pointer is not NULL: 检查FILE指针是否不为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: 我不知道这是否对您有帮助,但这是我从C程序执行gnuplot的方法:

  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. 我创建了一个模板文件(通常不删除它,以便更轻松地进行故障排除),所有gnuplot命令都编写在其中。

  2. I run gnuplot with 我用gnuplot运行

     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 凯里奥·沃尔坦(Cherio Woltan)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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