Hello everyone,

I am trying to call gnuplot in c++ code using pipe in linux. There is no errors during compilation, building and excecution. However, window with the plot does not appear. Below is the code.

FILE* Gplt = popen("gnuplot -persist","w");
	fprintf(Gplt,"plot '/home/mk/nh1.dat' using 100 with lines");	
	pclose(Gplt);

What is the possible reason of such behaviour?

Recommended Answers

All 2 Replies

What is the possible reason of such behaviour?

gnuplot is line buffered and you do not send a newline to the application. Try:

fprintf( Gplt, "plot '/home/mk/nh1.dat' using 100 with lines\n");

You may need to fflush (Gplt); to ensure that the buffer is written to the application depending on your context.

commented: thats work +1

Thanks, that's work fine

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.