1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

How to execute a program by using a C++ program's command?

Discussion in 'Hardware, Software & Troubleshooting' started by Helgso, Jul 18, 2008.

  1. Helgso

    Helgso Helgso

    Joined:
    Dec 5, 2005
    Messages:
    200
    Likes Received:
    0
    I'm playing around with the C++ language and I got the idea of a program that executes a desired game. It simply gives you a list of games, which you can then choose which you want to run. (Already done so).

    Now, I was going to make the program so when you picked a game it would start it automatically but then I hit the end of my knowledge.

    The thing is, is there any command you know that would make the C++ program run another program? Example:

    Code:
    main()
    {
          int selection // Tells the program to store information about which game is picked
    
          cout<<"Select a game to start: \n"; // cout is the command to display messages
          cout<<"\n";
          cout<<"1. Unreal Tournament\n";
          cout<<"2. UT2K4\n";
          cout<<"3. UT3
          cout<<"4. Unreal\n";
          cin>> selection; //Tells the program to store the number 1, 2, 3 or 4 to its memory
          if ( selection == 1 ){
                [b]execute "C:\UnrealTournament\System\UnrealTournament.exe";[/b]
          }
    
    SO, at the bottom where I say "execute" (it is highlighted, and It's not the correct command), I want the program to run Unreal Tournament. IS THIS POSSIBLE? To make the program execute Unreal Tournament? IS C++ BUILT TO BE ABLE TO RUN OTHER PROGRAMS?

    HELP HIGHLY APPRICIATED. THANKS!
     
  2. Continuum

    Continuum Lobotomistician

    Joined:
    Jul 24, 2005
    Messages:
    1,305
    Likes Received:
    0
    Quickest way would be the system("path to execute")
    There are probably a dozen other ways could be used if that one didn't work.
     
  3. Helgso

    Helgso Helgso

    Joined:
    Dec 5, 2005
    Messages:
    200
    Likes Received:
    0
    So it should state?:

    system("C:\UnrealTournament\System\UnrealTournament.exe");

    I tried it out but then my compiler CodeBlocks said:
    Code:
    ||===  Debug ===|
    |35|incomplete universal character name \U|
    |35|warning: unknown escape sequence '\S'|
    |35|incomplete universal character name \U|
    
    So, it didn't work. Do you know any link to a website that might be able to help me?
     
  4. Helgso

    Helgso Helgso

    Joined:
    Dec 5, 2005
    Messages:
    200
    Likes Received:
    0
    YAY!

    I got it to work!!

    It's not supposed to be:

    Code:
    system("C:\UnrealTournament\System\UnrealTournament.exe");
    It's supposed to be:

    Code:
    system("C:\\UnrealTournament\\System\\UnrealTournament.exe");
    MANY THANKS!
     
  5. Paderburner

    Paderburner New Member

    Joined:
    Aug 14, 2010
    Messages:
    1
    Likes Received:
    0
    Hey Helgso,
    how did u come to that solution? Do u know, why an additional backslash is necessary?

    Its interesting me
     
  6. Wormbo

    Wormbo Administrator Staff Member

    Joined:
    Jun 4, 2001
    Messages:
    5,913
    Likes Received:
    36
    Backslash is the escape character, so in order to use it as a regular backslash, it needs to be escaped, hence an additional backslash before each actual backslash.
     

Share This Page