Passing parameters in pipes

Hi ! I'm trying to plot some result using gnuplot. To do this, I've declared a pipe between my program and he gnuplo executable.

The problem is that the user define the path where the data to plot are, but when I pass it through the pipe, it's not recognized. I've got this


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#define GNUPLOT_PATH "./gnuplot"

        ...........

        string path;
        cout << "Insert the path of the 'input.dat';
        cin >> path;

        ..........


        FILE * gp;
	
	gp = popen (GNUPLOT_PATH, "w");
	
	if (gp == NULL)
	{
		fprintf(stderr, "Can't find path %s.", GNUPLOT_PATH);
	 	exit(EXIT_FAILURE);
	}
	
	if (n_var == 1)
	{
		fprintf(gp, "set title 'Regresion Simbolica' \n");
		fprintf(gp, "set style data lines \n ");
		fprintf(gp, "plot path, 'p_salida.dat'");
	}
	
	fflush(gp);
	
	pclose(gp);
	
	return(EXIT_SUCCESS); 


Any idea about it? How can I pass it? :( Thanks
Last edited on
Nobody? :(
If path is a variable you're trying to place into that fprintf, should it not be something more like this?

fprintf(gp, "plot" %s, 'p_salida.dat'", path);
Hi ! Iv'e made this as you said:

fprintf(gp, "plot %s , './p_salida.dat' ls 2 title 'Resultados_Salida' \n", path);

But when I compile it produces:

warning: cannot pass objects of non-POD type ‘struct std::string’ through ‘...’; call will abort at runtime

And the execution produces a Bus error. Any idea? :S :(

Thanks !

PD: yes, path is a string variable wich indicates the name of a .dat file
Last edited on
Path is a std::string, and the %s indicates that you'll be passing in a c-style string.

You can turn a std::String into a c-style string like this: path.c_str()

so try

fprintf(gp, "plot" %s ", './p_salida.dat' ls 2 title 'Resultados_Salida' \n", route.c_str());

I assume that what you used to call path you now call route.
Ok, now there's no warning in the compilation, but the executions continues producing a Bus error.

I've made a backtrace full, and here it is :
1
2
3
4
5
6
7
8
9
10
11
12
13
#0  0x93992f30 in strlen ()
No symbol table info available.
#1  0x9398cb71 in __vfprintf ()
No symbol table info available.
#2  0x939bfe67 in vfprintf_l ()
No symbol table info available.
#3  0x939bfdf9 in fprintf ()
No symbol table info available.
#4  0x00002935 in Algoritmo::Imprime_Grafica (this=0xbffff8cc) at Algoritmo.H:622
	gp = (FILE *) 0xa048f4c0
	path = 0x1002ec "puntos2.dat"

......



There's an strange error in strlen or something like this, but I've got no idea :S :(

Thanks again !
Ok man, I put some aditional flags and now works perfectly !!! Many many thanks !!!!
Last edited on
Topic archived. No new replies allowed.