Running Exe in C++ Code.

This is a discussion on Running Exe in C++ Code. within the C++ Programming forums, part of the General Programming Boards category; Executing an exe at runtime Basically i am creating a D3d App and I want the code to run this ...

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

    Running Exe in C++ Code.

    Executing an exe at runtime

    Basically i am creating a D3d App and I want the code to run this configuration (choose resolution, windowed or fullscreen, etc...)

    then this config.exe will save the settings to a settings.cfg then the D3D app runs and refers to the information from the settings.cfg

    is this possible? how do I do this? I want the code to run an exe file basically.

    i also want to make sure that config.exe finsihes (ie exits) then the code runs the main program.

    THx.
    Last edited by Ti22; 03-22-2006 at 01:32 PM.
    -Ti22-

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    yes that can be done. How, depends on the operating system because you have to call os-specific functions. In MS-Windows you can use CreateProcess() for greatest flexibility, although there are other function slightly easier to use. *nix I think you would use one of the spawn() family of functions.

  3. #3
    Registered User
    Join Date
    Jan 2006
    Location
    Europe/Belgrade
    Posts
    78
    The simplest is system(), but it's not recommended for security reasons.

  4. #4
    ♥Sexy Coding Hunk♥ CartoonLarry's Avatar
    Join Date
    Dec 2003
    Location
    Michigan
    Posts
    50
    I want the code to run an exe file basically.

    i also want to make sure that config.exe finsihes (ie exits) then the code runs the main program.
    Here are a couple that may help you:

    Running the exe and waiting using _spawnlp:

    Code:
    _spawnlp (_P_WAIT, "config.exe", "config.exe", Argument1 , Argument2, NULL);
    Or

    Running the exe and waiting using CreateProcess and WaitForSingleObject:

    Code:
       PROCESS_INFORMATION ProcessInfo;
    
       StartupInfo.cb = sizeof(STARTUPINFO);
       if (CreateProcess(NULL, "config.exe", NULL, NULL, FALSE,0, NULL, NULL, &StartupInfo, &ProcessInfo))
       {
           WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
       }
       else
       {
           // Do something else...
       }
    Hope this helps.
    Last edited by CartoonLarry; 03-23-2006 at 07:04 AM.

  5. #5
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    Last edited by Ideswa; 03-23-2006 at 07:54 AM.
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  6. #6
    Registered User
    Join Date
    Jan 2004
    Posts
    68
    thx guys got it working.
    -Ti22-

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. running code in borland
    By Aisthesis in forum Tech Board
    Replies: 5
    Last Post: 05-19-2009, 12:06 AM
  2. problem running code
    By michaelp in forum C++ Programming
    Replies: 4
    Last Post: 02-19-2008, 07:52 PM
  3. Replies: 9
    Last Post: 10-18-2004, 09:14 AM
  4. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Linux Programming
    Replies: 0
    Last Post: 10-14-2002, 01:30 PM
  5. get code out exe
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 04-15-2002, 05:30 AM

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