1

My code is

int gnuplot() {

    FILE *gnu;
    gnu = _popen(" gnuplot ", "r");

    fprintf(gnu, "plot \'C:/Users/user/Documents/gnuplot/cpp/FFT/file.dat\' with linespoints \n ");

    fflush(gnu); // I'm not sure how or if this will help, I thought it was related

    _pclose(gnu);

     return 0;
}

At the moment I am able to just open the CMD window of the gunplot window but not enter the plot command or exit it.

1
  • Just to let you know. There is a gnuplot C++ interface available here Commented May 2, 2016 at 20:23

1 Answer 1

5
gnu = _popen(" gnuplot ", "r");

It should be write mode instead.

gnu = _popen("gnuplot ", "w");
Sign up to request clarification or add additional context in comments.

4 Comments

Sorry I whould have added that I tried that already. If I change "r" to "w" it opens it and closes it quickly, barely noticeble. same if I remove the line _pclose(gnu);. how can I make it close the cmd but keep the gnuplot window open?
One approach: plot to image file, so you don't need to keep the gnuplot window open
Another approach: Use system("gnuplot -e \"plot \'C:/Users/user/Documents/gnuplot/cpp/FFT/file.dat\' with linespoints\""); instead of popen.
This is my code now, it yields me gnuplot is not recognized and no files created. FILE *gnuopener; gnuopener = _popen(" gnuplot ", "w"); fprintf(gnuopener, "plot \'C:/Users/yes/Documents/gnuplot/cpp/FFT/jesus.dat\' with linespoints\n"); fprintf(gnuopener, "set term postscript\n"); fprintf(gnuopener, "set output \"jesus.ps\" \n"); fprintf(gnuopener, "replot\n"); fprintf(gnuopener, "set term png\n"); fprintf(gnuopener, "set output \"jesus.png\" \n"); fprintf(gnuopener, "replot\n"); fprintf(gnuopener, "set term win \n"); _pclose(gnuopener);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.