Student question on external calls.

Discussion in 'C++' started by Hagar, Apr 20, 2004.

  1. Hagar

    Hagar Guest

    I am currently learning C++ and am into a project for the end of the
    semester finals. Everything is rosy except for one feature that I want
    to include and can't find in my very large and expensive C++ books. Plus,
    I don't want to ask the instructor because that will give my project away.

    How do you call an external non C++ program, or possibly a system
    function? For instance, I have some very good Perl modules from my last
    class that parse text files and I would like to call them from a menu in
    my C program. (Why the heck, you say? Because in theory, my program can
    call external scripts that can be changed by the assumed user and if they
    were compiled into MAIN then they would be fixed functions. Remember,
    this is for credit, not deployment.)

    But I don't find anything (or maybe don't recognize it) in
    my manuals - calling, external calls, external functions, system, system
    calls, etc - apparently none of the above. I even spent some time in the
    local Booksamillion looking through their stacks (for free, I admit it)
    and didn't find the keyword I am looking for.

    What is interesting is that I can easily call a C program from a Perl
    script, but not the other way around.

    Anybody?

    Thanks all
    Hagar (but not too horrible).
     
    Hagar, Apr 20, 2004
    #1
    1. Advertising

  2. Hagar

    Rakesh Kumar Guest

    Therez a C function by name - 'system (<path_to_exec> ) ' that can do
    what you want ! Check it out in google.

    Hagar wrote:

    > I am currently learning C++ and am into a project for the end of the
    > semester finals. Everything is rosy except for one feature that I want
    > to include and can't find in my very large and expensive C++ books. Plus,
    > I don't want to ask the instructor because that will give my project away.
    >
    > How do you call an external non C++ program, or possibly a system
    > function? For instance, I have some very good Perl modules from my last
    > class that parse text files and I would like to call them from a menu in
    > my C program. (Why the heck, you say? Because in theory, my program can
    > call external scripts that can be changed by the assumed user and if they
    > were compiled into MAIN then they would be fixed functions. Remember,
    > this is for credit, not deployment.)
    >
    > But I don't find anything (or maybe don't recognize it) in
    > my manuals - calling, external calls, external functions, system, system
    > calls, etc - apparently none of the above. I even spent some time in the
    > local Booksamillion looking through their stacks (for free, I admit it)
    > and didn't find the keyword I am looking for.
    >
    > What is interesting is that I can easily call a C program from a Perl
    > script, but not the other way around.
    >
    > Anybody?
    >
    > Thanks all
    > Hagar (but not too horrible).


    --

    --
    Rakesh Kumar
    ** Remove nospamplz from my email address for my real email **
     
    Rakesh Kumar, Apr 20, 2004
    #2
    1. Advertising

  3. Hagar

    Jeff Schwab Guest

    Hagar wrote:

    > How do you call an external non C++ program, or possibly a system
    > function? For instance, I have some very good Perl modules


    ....

    > What is interesting is that I can easily call a C program from a Perl
    > script, but not the other way around.


    To pass arbitrary commands to your execution environment, use the
    "system" function from <cstdlib>. Perl also has excellent facilities
    for being embedded in C and C++ programs.

    http://search.cpan.org/~abergman/ponie-2/perl/pod/perlembed.pod

    3rd-party libraries are available to make it even easier. E.g., see:

    http://search.cpan.org/~jtobey/pickle-0.5.1/pickle.pod
     
    Jeff Schwab, Apr 20, 2004
    #3
  4. Hagar

    Hagar Guest

    > But I don't find anything (or maybe don't recognize it) in
    > my manuals - calling, external calls, external functions, system, system



    Thanks guys. Interestingly, system is what perl uses to call outside the
    main code. But... There is not a single reference to the system command
    in either of my C++ books, or popen or exec which others have suggested -
    apparently, students aren't supposed to move outside of the box.

    Obviously, what I need is a genuwine C++ book from a non-college
    bookstore. However, even though those don't cost as much as the ripoff
    price of textbooks, they still are not cheap, studentwise. Maybe I can
    code some rich kids homework for the price:)

    Thanks
    Hagar (but not too horrible).
     
    Hagar, Apr 20, 2004
    #4
  5. Hagar

    red floyd Guest

    Hagar wrote:
    >>But I don't find anything (or maybe don't recognize it) in
    >>my manuals - calling, external calls, external functions, system, system

    >
    >
    >
    > Thanks guys. Interestingly, system is what perl uses to call outside the
    > main code. But... There is not a single reference to the system command
    > in either of my C++ books, or popen or exec which others have suggested -
    > apparently, students aren't supposed to move outside of the box.
    >
    > Obviously, what I need is a genuwine C++ book from a non-college
    > bookstore. However, even though those don't cost as much as the ripoff
    > price of textbooks, they still are not cheap, studentwise. Maybe I can
    > code some rich kids homework for the price:)


    No. popen() and exec() won't be in any book describing C++, as they
    aren't part of the Standard. They would be in a book describing "C++
    Programming in a [YOUR_OS_HERE] Environment".

    I don't recall whether system() is part of the Standard either, but it
    would be described in the second type of book ("C++ for XXX Environment").
     
    red floyd, Apr 20, 2004
    #5
  6. Hagar

    Default User Guest

    Hagar wrote:

    > Thanks guys. Interestingly, system is what perl uses to call outside the
    > main code. But... There is not a single reference to the system command
    > in either of my C++ books,


    That's a failing.

    > or popen or exec which others have suggested -


    There are no such things in C++. Some implementations have extensions by
    these names, but unless your book specificially covers that platform, it
    would not be unusual for it not to mention them. You don't mention which
    books you are using.

    > apparently, students aren't supposed to move outside of the box.


    I don't understand this statement.

    > Obviously, what I need is a genuwine C++ book from a non-college
    > bookstore. However, even though those don't cost as much as the ripoff
    > price of textbooks, they still are not cheap, studentwise. Maybe I can
    > code some rich kids homework for the price:)


    Check your local public library, it may have useful books.


    Brian Rodenborn
     
    Default User, Apr 20, 2004
    #6
  7. Hagar

    Default User Guest

    red floyd wrote:

    > I don't recall whether system() is part of the Standard either, but it
    > would be described in the second type of book ("C++ for XXX Environment").


    Yes, it is.



    Brian Rodenborn
     
    Default User, Apr 20, 2004
    #7
  8. Hagar

    Hagar Guest

    >
    >> Thanks guys. Interestingly, system is what perl uses to call outside the
    >> main code. But... There is not a single reference to the system command
    >> in either of my C++ books,

    >
    > That's a failing.



    As my instructor says, textbooks are to make publishers money - they have
    nothing to do with teaching or learning - unfortunately, they are also
    mandated by the state based on the amount of donations received by
    politicians from publishers.


    n't supposed to move outside of the box.
    >
    > I don't understand this statement.
    >

    Just some minor sarcasm.


    > Check your local public library, it may have useful books.
    >


    Brian - You are not from East Texas, are you? In our only public library
    there are books about the latest advances in V2 rocketry, history books
    that speculate on what the world will be like after WWII ends, the latest
    research on vacuum tube radios, and info on something called a wire
    recorder that actually records voices.

    Oh yes. There is also a programming book. It is about Autocoder
    that runs on an IBM 1401 ??? (whatever the heck that is).


    I think I better wait till I have the money to visit a real Dallas book
    store.

    Hagar
     
    Hagar, Apr 21, 2004
    #8
  9. Hagar

    Default User Guest

    Hagar wrote:

    > > Check your local public library, it may have useful books.
    > >

    >
    > Brian - You are not from East Texas, are you?


    No.

    > Oh yes. There is also a programming book. It is about Autocoder
    > that runs on an IBM 1401 ??? (whatever the heck that is).


    Almost any library can get books via inter-library loan.




    Brian Rodenborn
     
    Default User, Apr 21, 2004
    #9
    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. Chen Bin

    A student's question

    Chen Bin, Aug 31, 2003, in forum: VHDL
    Replies:
    7
    Views:
    538
  2. Honne Gowda A
    Replies:
    2
    Views:
    913
    Karl Heinz Buchegger
    Oct 31, 2003
  3. andy6
    Replies:
    2
    Views:
    793
    andy6 via DotNetMonster.com
    Jun 9, 2006
  4. Richard Tobin
    Replies:
    24
    Views:
    825
  5. Bob
    Replies:
    5
    Views:
    290
Loading...

Share This Page