gnuplotPipe = popen("/usr/bin/gnuplot -persist", "w");
if (gnuplotPipe)
{
fprintf(gnuplotPipe, "plot \"%s\" with lines\n", DataFileName);
fflush(gnuplotPipe);
DataFile = fopen(DataFileName, "w");
for (i = 0; i < dataSize; i++)
{
x = data[i].x;
y = data[i].y;
fprintf(DataFile, "%lf %lf\n", x, y);
}
fclose(DataFile);
fflush(gnuplotPipe);
pclose(gnuplotPipe);
remove(DataFileName);
}
I am writing a piece of code that tries to open a pipe with gnuplot for plotting data.
According to the documentation, pclose() should wait for the associated process to terminate and returns the exit status of the command as returned by wait4().
However, there is something wrong since the program terminates with still gnuplot opened in a window.
Doesn't pclose() wait for the gnuplot process to terminate? Where am I wrong? :D