scu-ba-de-buntu
March 14th, 2011, 04:49 AM
Hi, I need to plot data and I would like to use gnuplot. I would like to send (gnuplot formated) instructions to gnuplot and have it render the changes in real-time. To do this I was thinking I could just send a new 'plot' command, but that means I need to create and maintain a writable pipe between my program and gnuplot.
This is a stripped down example. How could I make this work?
solved. needed \n
#include <sys/wait.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <iostream>
int main(int argc, char *argv[])
{
int pfd[2];
pid_t cpid;
char buf;
FILE *fp;
fp = popen("gnuplot", "w");
if (fp == NULL){/*ERROR*/_exit(0);}
char buffer[] = {"\nplot sin(x)/x\n"};
fwrite (buffer , 1 , sizeof(buffer) , fp );
fflush(fp);
getchar();
pclose(fp);
getchar();
}
Please and Thanks!
This is a stripped down example. How could I make this work?
solved. needed \n
#include <sys/wait.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <iostream>
int main(int argc, char *argv[])
{
int pfd[2];
pid_t cpid;
char buf;
FILE *fp;
fp = popen("gnuplot", "w");
if (fp == NULL){/*ERROR*/_exit(0);}
char buffer[] = {"\nplot sin(x)/x\n"};
fwrite (buffer , 1 , sizeof(buffer) , fp );
fflush(fp);
getchar();
pclose(fp);
getchar();
}
Please and Thanks!