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
Printable View
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
Try
system("\"D:\\Unreal Tournament\\System\\unrealtournament.exe\"");
thanks man that worked great.
Can you explain me what adding "\" and \" does?
Just I would like to know for feature refereances
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.
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
just use a relative path...
what do u mean?Quote:
Originally posted by Stoned_Coder
just use a relative path...
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.
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
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?
Do you really need to use the double \'s in strings?
here is a part of the code:
as you can see i need all differnt path.sCode: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;
Then you will have to use absolute paths or better if possible to retrieve the information neede from the registry.
break will have no effect after exit is called because exit will cause your program to cease anyway.
> 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.