1
votes

Trying to open a pipe to Gnuplot in a simple C program, with

FILE *pipe=popen("gnuplot - persist", "w");

receiving the above error. I have installed Gnuplot using Macports and the gnuplot command works straight off using the bash terminal, but I cannot access it via the code above (sh).

I have tried adding a .MacOSX with an environment.plist file (a suggestion I found online) but I cannot seems to get anything to work (using the explicit location of Gnuplot in the code doesn't seem to work for me either). Sorry if this is an obvious problem, I am very new to programming and I just want to plot some graphs! Thanks

2

2 Answers

2
votes

If you installed with MacPorts then gnuplot is probably in /opt/local/bin/gnuplot. But you can check with in the Terminal with "which gnuplot". Try

gnuplot = popen("/opt/local/bin/gnuplot --persist", "w");
if (gnuplot != NULL)
  fprintf(gnuplot, "plot sin(1/x)\n");

for example. You have a weird space in your command string before "persist".

1
votes

How do you start your program? Do you change the PATH variables? Before popen do

printf("PATH=%s\n", getenv("PATH"));

what's the result of this?