system() function problem

May 19, 2011 at 7:15pm
Hey guys sorry but I just started programming like 2 weeks ago, and I recently hit a snag with using system() function to run start a program.

It works just fine when referring to a file location that has no spaces.
ex. system("Drive/stuff/example/file.exe")

but I cannot get it to work with things that have spacing in the file names.
ex. system("C:/Program Files (x86)/RIFT Game/playrift.exe")

if anyone could help me understand why its not working or show me a better way of doing this (remembering I am a beginner) I would greatly appreciate it.
May 19, 2011 at 7:21pm
This is because the shell thinks that you're calling a program named RIFT with the argument Game/playrift.exe. If the Windows shell is anything like most *nix consoles, putting quotes around (EDIT: Actually, the entire string. Duoas is right.) should fix it.

Happy programming!

-Albatross
Last edited on May 19, 2011 at 8:35pm
May 19, 2011 at 8:30pm
Put quotes around the entire string:

"\"C:/Program Files (x86)/RIFT Game/playrift.exe\""

BTW, you shouldn't hardcode paths like that one...
May 19, 2011 at 11:24pm
BTW, you probably shouldn't be using system. http://www.cplusplus.com/forum/articles/11153/
Besides, that looks more like something in a batch script ¿What are you trying to do?
May 20, 2011 at 12:11am
I am just trying to get down a few different ideas but the program I am trying to make a program that acts as a list to start other programs, dumb and useless I know but I am a beginner.

so for instance I am making it like this

1. Game Name
2. Game Name
3. Game Name
4. Game Name
5. Game Name

Please select one.

THen you enter the number corresponding to the program you want to start, the only problem I have encountered is file location with a space in the naming.

to get practice I am setting this up as an If Then Else statement like a check list of if its 1 do this else if its 2 do this else etc.
Last edited on May 20, 2011 at 12:16am
May 20, 2011 at 1:58am
That's a good project.

Hint: use a file that lists the game name and its start command. Something like this:

Pac-Man
"C:\Program Files\DOS Games\Pacman\pac.exe"

Jazz Jackrabbit
"C:\Program Files\DOSBox\dosbox.exe" C:\PROGRA~1\DOSGAM~1\Jazz\jazz.exe -exit -fullscreen

Bouncing Babies
"C:\Program Files\DOSBox\dosbox.exe" C:\PROGRA~1\DOSGAM~1\bbabies\baby.exe -exit -fullscreen -conf C:\PROGRA~1\DOSGAM~1\bbabies\baby_dosbox.conf

Etc.

Hope this helps.
Last edited on May 20, 2011 at 1:59am
Topic archived. No new replies allowed.