473,394 Members | 2,160 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,394 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 6931
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, I´m using Gnuplot via gnuplot.py and I´m 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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.