473,246 Members | 1,298 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 software developers and data experts.

gnuplot and system()

I'm trying to use the system() in a C++ program to execute gnuplot on
a file of data on OSX and have the graph pop up but so far the only
thing I've managed to do is get gnuplot to open.

as I minor test I did (unrelated stuff excised)

#include <stdlib.h>
int system(const char *string);
system("gnuplot");
system("plot sin(x)");
and the only thing that happened was gnuplot opening in terminal. For
that matter typing

plot sin(x) doesn't do anything even if it is typed manually into
terminal with gnuplot started. The graph only pops up if I enter it
directly into the console that opens when clicking on gnuplot in
finder. Anyway to fix this or more easily load a file to gnuplot from
the other program?

Jun 25 '07 #1
2 6900
Blah wrote:
I'm trying to use the system() in a C++ program to execute gnuplot on
a file of data on OSX and have the graph pop up but so far the only
thing I've managed to do is get gnuplot to open.

as I minor test I did (unrelated stuff excised)

#include <stdlib.h>
int system(const char *string);
system("gnuplot");
system("plot sin(x)");
and the only thing that happened was gnuplot opening in terminal. For
that matter typing

plot sin(x) doesn't do anything even if it is typed manually into
terminal with gnuplot started. The graph only pops up if I enter it
directly into the console that opens when clicking on gnuplot in
finder. Anyway to fix this or more easily load a file to gnuplot from
the other program?
How system works is implementation-defined, so how to use it will depend on
your compiler. But to give you a hint, this works on my system:

std::ofstream file("file");
file << "plot sin(x)\n";
file.close();
std::system("gnuplot file");

If you want a more system specific solution, not creating a file, try:

#include <cstdio>
std::FILE *f = popen("gnuplot", "w");
std::fputs("plot sin(x)\n", f);
std::fflush(f);
....
std::fclose(f);

popen() is, however not part of the C++ standard library, so the discussion
of it would be off topic here.

--
rbh
Jun 25 '07 #2
In article <11**********************@g37g2000prf.googlegroups .com>,
Blah <ci*******@yahoo.comwrote:
>I'm trying to use the system() in a C++ program to execute gnuplot on
a file of data on OSX and have the graph pop up but so far the only
thing I've managed to do is get gnuplot to open.

as I minor test I did (unrelated stuff excised)

#include <stdlib.h>
int system(const char *string);
system("gnuplot");
system("plot sin(x)");
This is not even close to correct.
You don't want system();
you want popen(), followed by a series of fprintf() calls to pass
in commands.
..

--
Ethan A Merritt
Jun 25 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Rama Calaga | last post by:
Hi, I use both python and gnuplot a lot, but I am unable to find a way to embed gnuplot "window/canvas" into tkinter. BLT option in PMW is not so powerful and not so great, any suggestions ?? ...
9
by: syd | last post by:
I don't even know where to begin. This is just bizarre. I just picked up the Gnuplot.py module (a light interface to gnuplot commands) and was messing around with it today. I've got a tiny...
6
by: Joseph Suprenant | last post by:
Hello all, I have a C++ program, it does some calculations on things and then prints out a file in the format in which GNUPLOT can use. So my question is how would i call GNUPLOT from my C++...
4
by: Alexander Stippler | last post by:
Hello, I want to visualize numerical results with gnuplot. The easiest way would be to use a pipe to gnuplot. But I want to be platform independent, just relying on the C++-standard. What is...
3
by: Bernhard Hidding | last post by:
Hello, my c++ programm produces a variable number of ASCII files with variable file names. These are to be plotted in with gnuplot. I use system("gnuplot -persist my_gnuplot_script.gpl"); to...
1
by: Nicola Kaiser | last post by:
Hi, Im using Gnuplot via gnuplot.py and Im looking for a way to get the plotting output (terminal set to png in my case) piped in a string instead of to stdout or a file. Is there any...
0
by: bwaha | last post by:
I've posted this question to comp.graphics.apps.gnuplot too but given that this python group may also comprise a lot of gnuplot users, and is far more active, I've posted this question here too. My...
0
by: Titi Anggono | last post by:
Hi all, I made 2 arrays, which are i and uzuy (both are float). And I want to plot the graph between those arrays. I followed from the manual ==================
3
by: Peter Beattie | last post by:
I am trying to plot something in gnuplot 4.2 using co-ordinates a Python 2.5 program computes. Here's what I'm doing: pyfrom subprocess import * pyplot = Popen("c:/progs/gp/bin/wgnuplot.exe",...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.