By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,273 Members | 1,037 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,273 IT Pros & Developers. It's quick & easy.

how to call an external program?

P: n/a
Is there a standard way in C++ to call an external program or is this
platform dependent?

If it is platform dependent, can somebody drop a line what to use or
where to look for info for GNU C++ on RedHat? I am doing some numerical
calculations and need to invoke an external plotting program (gnuplot)
and return to the numerics.

Sorry if I posted twice.

Thanks,
Sanyi

Jul 22 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
On Sat, 13 Dec 2003 22:48:28 -0500, Sanyi Benczik wrote:
Is there a standard way in C++ to call an external program or is this
platform dependent?

If it is platform dependent, can somebody drop a line what to use or
where to look for info for GNU C++ on RedHat? I am doing some numerical
calculations and need to invoke an external plotting program (gnuplot)
and return to the numerics.


I don't know how platform independent this is, but <stdio.h> contains:
FILE *popen(const char *command, const char *type);
This allows you to open a program and either read stdin ("r") or write stdout
("w") in the same manner as fopen.

There is probably a better solution, but this is the first thing that came
to mind.

-Brian
Jul 22 '05 #2

P: n/a
man system 3

Sanyi Benczik wrote:
Is there a standard way in C++ to call an external program or is this
platform dependent?

If it is platform dependent, can somebody drop a line what to use or
where to look for info for GNU C++ on RedHat? I am doing some numerical
calculations and need to invoke an external plotting program (gnuplot)
and return to the numerics.

Sorry if I posted twice.

Thanks,
Sanyi


Jul 22 '05 #3

P: n/a
Sanyi Benczik <sb******@vt.edu> wrote in message news:<br**********@solaris.cc.vt.edu>...
Is there a standard way in C++ to call an external program or is this
platform dependent?

If it is platform dependent, can somebody drop a line what to use or
where to look for info for GNU C++ on RedHat? I am doing some numerical
calculations and need to invoke an external plotting program (gnuplot)
and return to the numerics.

Sorry if I posted twice.

Thanks,
Sanyi


I am not sure, but maybe System(char *) might seem helpful... Then you
can pipe the output to your program or something.
Jul 22 '05 #4

P: n/a
cm****@yahoo.com (Chris Mantoulidis) wrote in message news:<a8**************************@posting.google. com>...
Sanyi Benczik <sb******@vt.edu> wrote in message news:<br**********@solaris.cc.vt.edu>...
Is there a standard way in C++ to call an external program or is this
platform dependent?
#include <stdlib.h>

int system(const char* progCmdLin); // standard, fairly limited in
capability

If it is platform dependent, can somebody drop a line what to use or
where to look for info for GNU C++ on RedHat? I am doing some numerical
calculations and need to invoke an external plotting program (gnuplot)
and return to the numerics.
Depending how you want to design your program, you have a few options.

Popen is definitely one.

It might make sense to let the gnuplot program come up separately,
display your graph and stay there while the processing logic
continues.

Then you can spawn a process or a thread asynchronously to do that.
Lookup how to use system APIs. Look for the execle, execlp, execve,
execvp APIs plus the fork API.

Sorry if I posted twice.

Thanks,
Sanyi


I am not sure, but maybe System(char *) might seem helpful... Then you
can pipe the output to your program or something.

Jul 22 '05 #5

P: n/a
Sanyi Benczik wrote:
Is there a standard way in C++ to call an external program or is this
platform dependent?

If it is platform dependent, can somebody drop a line what to use or
where to look for info for GNU C++ on RedHat? I am doing some numerical
calculations and need to invoke an external plotting program (gnuplot)
and return to the numerics.


I believe that gnuplot has C and C++ interfaces. So you don't need to call
any extrenal program, just include some header files initialize it and link
with right libraries.

(At RH you probbably need to install gnuplot-devel RPM package)

See www.gnuplot.info

And then write me your experiences with this, please :-).

--
mP

http://pivoluska.matfyz.cz/
Jul 22 '05 #6

P: n/a
Brian Kerrick Nickel wrote:
On Sat, 13 Dec 2003 22:48:28 -0500, Sanyi Benczik wrote:

Is there a standard way in C++ to call an external program or is this
platform dependent?

If it is platform dependent, can somebody drop a line what to use or
where to look for info for GNU C++ on RedHat? I am doing some numerical
calculations and need to invoke an external plotting program (gnuplot)
and return to the numerics.

I don't know how platform independent this is, but <stdio.h> contains:
FILE *popen(const char *command, const char *type);
This allows you to open a program and either read stdin ("r") or write stdout
("w") in the same manner as fopen.

There is probably a better solution, but this is the first thing that came
to mind.

-Brian

FYI, "popen" is not a standard C++ function. I doesn't exist in at
least two of my compilers.
--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 22 '05 #7

P: n/a
Jeff Schwab wrote:
man system 3

Sanyi Benczik wrote:
Is there a standard way in C++ to call an external program or is this
platform dependent?

If it is platform dependent, can somebody drop a line what to use or
where to look for info for GNU C++ on RedHat? I am doing some
numerical calculations and need to invoke an external plotting program
(gnuplot) and return to the numerics.

Sorry if I posted twice.

Thanks,
Sanyi

Please do not reply with platform specific information
and also don't top-post.

Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.

C:\>man system 3
No manual entry for system
What manual page do you want from section 3?

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 22 '05 #8

P: n/a
Chris Mantoulidis wrote:
Sanyi Benczik <sb******@vt.edu> wrote in message news:<br**********@solaris.cc.vt.edu>...
Is there a standard way in C++ to call an external program or is this
platform dependent?

If it is platform dependent, can somebody drop a line what to use or
where to look for info for GNU C++ on RedHat? I am doing some numerical
calculations and need to invoke an external plotting program (gnuplot)
and return to the numerics.

Sorry if I posted twice.

Thanks,
Sanyi

I am not sure, but maybe System(char *) might seem helpful... Then you
can pipe the output to your program or something.


BTW, the function is "system". The C++ language is case-sensitive,
"system" and "System" are different identifiers.
--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 22 '05 #9

P: n/a


Thomas Matthews wrote:
Jeff Schwab wrote:
man system 3
Please do not reply with platform specific information


Sorry; my mistake!

<ot> and also don't top-post.


Top-posting has gotten a bad rap. I'm bringing it back into fashion! :)
Seriously, I think it's often appropriate, but I guess that's sort of
a dead horse... <grumble/><grumble/>

</ot>

Jul 22 '05 #10

P: n/a
> BTW, the function is "system". The C++ language is case-sensitive,
"system" and "System" are different identifiers.


I know C++ is case-sensitive (d'oh)... I just haven't used
sytem(char*) for a long time. I don't really need it... I have other
alternatives ;)

cmad
Jul 22 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.