[英]hide C++ Gnuplot pipe console output
In C++
I'm currently using this bit of code to plot some data using gnuplot
. 在
C++
我目前正在使用这段代码使用gnuplot
绘制一些数据。 Gnuplot
's fit
command, however, produces a lot of unwanted output on the command line console (which I use for outputting some other stuff too, throughout the rest of my program). 但是,
Gnuplot
的fit
命令会在命令行控制台上产生很多不需要的输出(在我的程序的其余部分中,我也使用它们来输出其他内容)。
Since this output clutters up my console output, I would like to disable it. 由于此输出会使我的控制台输出混乱,因此我想禁用它。 There should be 2 ways to do this:
应该有两种方法可以做到这一点:
pipe
in C++
C++
pipe
创建的输出 gnuplot
to be silent and not output that much gnuplot
保持沉默并且不输出太多 FILE *pipe = popen("gnuplot -persist", "w");//open up a pipe to gnuplot
fprintf(pipe, "set terminal x11 enhanced\n"); //set appropriate output terminal for the plot
fprintf(pipe, "set xlabel 'N'\n");//set xlabel
fprintf(pipe, "set ylabel 'error'\n");//set ylabel
fprintf(pipe, "set yrange [0:0.0001]\n");//set the y range
fprintf(pipe, "plot 'dataSimp.dat' ti 'Simpson method'\n");//plot the Simp error
fprintf(pipe, "replot 'dataTrap.dat' ti 'Trapezium method' \n");//plot the Trap error
fprintf(pipe, "replot 1/(x**2) ti '1/{x^2}'\n");//plot y=1/(x^2) function for comparison
fprintf(pipe, "replot 1/(x**4) ti '1/{x^4}'\n");//plot y=1/(x^4) function for comparison
//fit curve to dataSimp
fprintf(pipe, "set output 'rommel.txt'");
fprintf(pipe, "fSimp(x)=aSimp/(x**4) \n");
fprintf(pipe, "fit fSimp(x) 'dataSimp.dat' via aSimp\n");
fprintf(pipe, "replot aSimp/(x**4) ti 'fitted aSimp/{x^4}'\n");
//fit curve to dataSimp
fprintf(pipe, "fTrap(x)=aTrap/(x**2) \n");
fprintf(pipe, "fit fTrap(x) 'dataTrap.dat' via aTrap \n");
fprintf(pipe, "replot aTrap/(x**2) ti 'fitted aTrap/{x^2}'\n");
pclose(pipe);//close gnuplot pipe
You could just use: 您可以使用:
FILE *pipe = popen("gnuplot -persist > /dev/null", "w")
Or, if gnuplot uses stderr: 或者,如果gnuplot使用stderr:
FILE *pipe = popen("gnuplot -persist > /dev/null 2>&1", "w")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.