running programs within c++

This is a discussion on running programs within c++ within the C++ Programming forums, part of the General Programming Boards category; I am aware of the use of ctsdlib's system() function I'm just wondering though, would that end the c++ program ...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    86

    running programs within c++

    I am aware of the use of ctsdlib's system() function

    I'm just wondering though, would that end the c++ program that is being run?

    for instance, if I'm runnign the program in a unix terminal and I use the command system("perl prog.pl") (which would tell unix to run a perl script) woudl my c++ program conitnue running after the perl script had ended?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    Yes it would

  3. #3
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    >would that end the c++ program that is being run?
    It's implementation dependent. So the answer is "maybe, but then again, maybe not".

  4. #4
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    In addition to that question, I have one.

    If I don't want to have the ugly "Press a key to end" or whatever, what's a more efficient way to pause the program until keypress?

  5. #5
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    >what's a more efficient way to pause the program until keypress?
    The best portable way is:
    Code:
    #include <ios>
    #include <iostream>
    #include <limits>
    
    using namespace std;
    
    int main()
    {
      //...
    
      cin.ignore(numeric_limits<streamsize>::max(), '\n');
      cin.get();
    }
    The call to ignore will clean up any extraneous characters from the stream so that get actually causes a blocking read. If your stream usage is well thought out then this shouldn't be a problem though.

    If you want to terminate the program at any key press rather than just at Enter, you get into the realm of implementation dependent solutions. In that case, the question becomes "How can I read a key press without waiting for Enter?".

  6. #6
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    Thanks, RoD. I've been wondering how to do that for a while, but I never even thought to ask here.

  7. #7
    Registered User
    Join Date
    Nov 2004
    Posts
    86
    this kinda got off topic

    what does implementation dependant mean?

    how do I set it up so that running the script doesn't end the c++ app?

  8. #8
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    >what does implementation dependant mean?
    It means the behavior of some construct is up to the compiler, or operating system, and the like. However, the implementation is required to document it's choice.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Recommend upgrade path for C programs
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-22-2007, 06:32 AM
  2. Monitor That Another App is Running
    By CodeButcher in forum Windows Programming
    Replies: 1
    Last Post: 01-18-2007, 12:34 PM
  3. Newbie question: pointers, other program's memory
    By xxxxme in forum C++ Programming
    Replies: 23
    Last Post: 11-25-2006, 12:00 PM
  4. help with running programs with c++
    By mendel69 in forum C++ Programming
    Replies: 5
    Last Post: 10-12-2006, 07:50 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21