Thread: Runing an Exe with c++

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    18

    Question Runing an Exe with c++

    How would I make a C++ program run another exe file? Like make my program to where if you press 1 it opens another program.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Since you didn't specify a compiler or operating system, the only way is to use the standard function system() in cstdlib:
    Code:
    #include <cstdlib>
    
    std::system ( "<path to the exe>" );
    My best code is written with the delete key.

  3. #3
    Registered User glUser3f's Avatar
    Join Date
    Aug 2003
    Posts
    345
    one way would be using function system:
    Code:
    system("path/to/exe");
    More info:
    http://www.cppreference.com/stdother...ls.html#system

    EDIT:
    you beat me to it Prelude
    Last edited by glUser3f; 01-12-2004 at 08:50 AM.

  4. #4
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Just remember how unsafe it is before using it!
    Do not make direct eye contact with me.

  5. #5
    Registered User trainee's Avatar
    Join Date
    Jan 2004
    Posts
    32
    Originally posted by Prelude
    Since you didn't specify a compiler or operating system, the only way is to use the standard function system() in cstdlib:
    Code:
    #include <cstdlib>
    
    std::system ( "<path to the exe>" );
    You sure it is std::system()? All thought all functions from C weren't included in the standard library?

    trainee

  6. #6
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Originally posted by trainee
    You sure it is std::system()? All thought all functions from C weren't included in the standard library?

    trainee
    They exist in the global namespace as well as the std namespace

    Also, isnt the original question in the FAQ?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to monitor exe and dll interactions?
    By George2 in forum C Programming
    Replies: 1
    Last Post: 10-26-2007, 04:22 AM
  2. how to run an exe command in c++ and get back the results?
    By mitilkhatoon in forum C++ Programming
    Replies: 5
    Last Post: 09-21-2006, 06:00 PM
  3. Close another exe from another exe??
    By Tony in forum Windows Programming
    Replies: 1
    Last Post: 06-12-2002, 07:19 AM
  4. insert another exe into exe
    By lliero in forum C Programming
    Replies: 8
    Last Post: 04-12-2002, 12:22 PM
  5. adding bytes to EXE to call another EXE
    By lliero in forum C Programming
    Replies: 2
    Last Post: 03-30-2002, 07:23 AM