how to call an external program?

Discussion in 'C++' started by Sanyi Benczik, Dec 14, 2003.

  1. 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
     
    Sanyi Benczik, Dec 14, 2003
    #1
    1. Advertising

  2. 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
     
    Brian Kerrick Nickel, Dec 14, 2003
    #2
    1. Advertising

  3. Sanyi Benczik

    Jeff Schwab Guest

    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
    >
     
    Jeff Schwab, Dec 14, 2003
    #3
  4. Sanyi Benczik <> wrote in message news:<brgmic$129$>...
    > 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.
     
    Chris Mantoulidis, Dec 14, 2003
    #4
  5. Sanyi Benczik

    Andy Guest

    (Chris Mantoulidis) wrote in message news:<>...
    > Sanyi Benczik <> wrote in message news:<brgmic$129$>...
    > > 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.
     
    Andy, Dec 14, 2003
    #5
  6. Re: Gnuplot C and C++ interfaces

    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/
     
    Matej Pivoluska, Dec 14, 2003
    #6
  7. 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
     
    Thomas Matthews, Dec 15, 2003
    #7
  8. 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
     
    Thomas Matthews, Dec 15, 2003
    #8
  9. Chris Mantoulidis wrote:

    > Sanyi Benczik <> wrote in message news:<brgmic$129$>...
    >
    >>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
     
    Thomas Matthews, Dec 15, 2003
    #9
  10. Sanyi Benczik

    Jeff Schwab Guest

    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>
     
    Jeff Schwab, Dec 16, 2003
    #10
  11. > 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
     
    Chris Mantoulidis, Dec 16, 2003
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tobias Merler
    Replies:
    0
    Views:
    500
    Tobias Merler
    Sep 24, 2003
  2. Scott Allen
    Replies:
    8
    Views:
    10,982
    Scott Allen
    May 2, 2004
  3. Philipp Neuhaus

    [NEWBIE] How to call an external program

    Philipp Neuhaus, Sep 18, 2003, in forum: Python
    Replies:
    1
    Views:
    322
    Ulrich Petri
    Sep 18, 2003
  4. guest7

    How to call external c++ program

    guest7, Jan 4, 2009, in forum: C Programming
    Replies:
    0
    Views:
    418
    guest7
    Jan 4, 2009
  5. Replies:
    8
    Views:
    138
    Tad McClellan
    Jun 19, 2006
Loading...

Share This Page