Thread: launch applications with spaces?

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    27

    launch applications with spaces?

    hey guys, new around here..

    My question is how can i run a program with spaces in it using the system command

    system("D:\\Unreal Tournament\\System\\unrealtournament.exe");

    Works fine with application which dont have spaces

    thank you

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Try

    system("\"D:\\Unreal Tournament\\System\\unrealtournament.exe\"");

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    27
    thanks man that worked great.

    Can you explain me what adding "\" and \" does?

    Just I would like to know for feature refereances

  4. #4
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    It adds a " character to the start and end of your string, so the OS knows your string doesn't end at the space you put in.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    27
    1 more question.

    Usins the same function, how can i lauch applications for a specified location.
    Example:

    I wanna run text.exe located in c:\test\ from the dir c:\test\ and not where the file was compliled

  6. #6
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    just use a relative path...
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  7. #7
    Registered User
    Join Date
    Jan 2002
    Posts
    27
    Originally posted by Stoned_Coder
    just use a relative path...
    what do u mean?

  8. #8
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    system("\"D:\\Unreal Tournament\\System\\unrealtournament.exe\"");

    that is an example of an absolute path.

    a relative path is so called because it is relative to the directory that you are in. For your apps that normally means their working directory.

    if we were in the directory Unreal Tournament then you could use...

    system("\\System\\unrealtournament.exe");

    That is a relative path. This would fail with a file not found error if you are currently in the wrong directory. It is best to use relative paths in your own code and if things need to be in a subdirectory then do it similar to the above example.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  9. #9
    Registered User
    Join Date
    Jan 2002
    Posts
    27
    ya but, the program I made is a list of programs. The user has a choice of 1-9. Then it launches the program fullpath

    Some dont work since its the wrong start dir. I need to know how i can launch a program from a dir

  10. #10
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    what directory is the menu prog in?
    what directory are the programs you want to fire up in?
    is the second a subdirectory of the first?
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  11. #11
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Do you really need to use the double \'s in strings?

  12. #12
    Registered User
    Join Date
    Jan 2002
    Posts
    27
    here is a part of the code:

    Code:
    case 3:
    			system("\"D:\\homm3\\heroes3.exe\"");
    			exit(-1);
    			break;
    		case 4:
    			system("\"D:\\homm3\\h3wog.exe\"");
    			exit(-1);
    			break;
    		case 5:
    			system("\"D:\\ee\\Empire Earth.exe\"");
    			exit(-1);
    			break;
    		case 6:
    			system("\"C:\\Program Files\\GameSpy Arcade\\Aphex.exe\"");
    			exit(-1);
    			break;
    as you can see i need all differnt path.s

  13. #13
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Then you will have to use absolute paths or better if possible to retrieve the information neede from the registry.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  14. #14
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    break will have no effect after exit is called because exit will cause your program to cease anyway.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  15. #15
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    > Do you really need to use the double \'s in strings?
    \ is a special character - \n represents a newline for example

    So
    system( "cd .\new" );
    would mean a directory containing a newline char (not likely)

    To get a real \ into the string, use two of them
    system( "cd .\\new" );

    > break will have no effect after exit is called because exit will cause your program to cease anyway
    This is true, but getting into the habit of always putting break statements in should prevent some headaches caused by code which falls-through when it shouldn't.

    But if exit() is being called in every case, then it should be moved out of the switch statement altogether, since it is common code, and then the break statments are necessary and correct.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Get Installed applications list and applications activity
    By arunarora in forum C++ Programming
    Replies: 5
    Last Post: 05-25-2009, 09:41 AM
  2. Changing 3 spaces to tabs
    By dnguyen1022 in forum C Programming
    Replies: 2
    Last Post: 12-22-2008, 12:51 AM
  3. A question about windows programming
    By Hussain Hani in forum Windows Programming
    Replies: 16
    Last Post: 05-23-2007, 07:38 AM
  4. Tabs or Spaces
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 46
    Last Post: 04-08-2007, 11:45 AM
  5. Replies: 5
    Last Post: 06-30-2003, 12:52 PM