Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Python (http://www.programmingforums.org/forum43.html)
-   -   Combining strings for os.system() (http://www.programmingforums.org/showthread.php?t=11279)

peaceofpi Sep 8th, 2006 6:52 PM

Combining strings for os.system()
 
Not working too well >_>

:

import os

map = raw_input("Enter map name: ") # ex. Town
gunzrun = "\"C:\\Program Files\\MAIET\\OldGunz\\GunzRunnable [02-06-06].exe\"" # (exe is C:\Program Files\MAIET\OldGunz\GunzRunnable [02-06-06.exe)
game = " /game \"" # the "/game" switch
eq = "\"" # quote mark at the end

full = gunzrun + game + eq
# after it's done, it turns out to be "C:\Program Files\MAIET\OldGunz\GunzRunnable [02-06-06].exe" /game "mapname"

os.system(full)


Output is:
'C:\Program\' is not recognized as an internal or external command, operable program or batch file.

Works right till then, how do I make the space in the string work?

peaceofpi Sep 8th, 2006 10:33 PM

Bleh, nevermind. I turned to VB (lol) and got a working GUI program for it

Ooble Sep 9th, 2006 8:00 AM

:

full = gunzrun + game + eq + map + eq

That's what you want.

peaceofpi Sep 9th, 2006 1:45 PM

Oh wow, thanks. I'd have never realized it, teehee

titaniumdecoy Sep 9th, 2006 3:56 PM

You should use os.path.join for this task to make your code (more) portable.

You should also use a Popen object from the subprocess module rather than os.system for the same reason.

You could also, as a matter of preference, prepend your paths with r to create raw strings so that you don't have to escape backslashes (unless the last character in the string is a backslash, in which case it must be escaped).

Arevos Sep 9th, 2006 5:13 PM

Since the Python code is running an exe file, I doubt portability matters.

titaniumdecoy Sep 13th, 2006 8:15 PM

C++ code runs in an exe file, so I suppose portability doesn't matter there, either?

DaWei Sep 13th, 2006 8:24 PM

You suppose right. Portability doesn't matter with an .exe file -- it's generally already blown to hell and gone. Portability is primarily a source code phenomenon. What good is a highly portable adjunct that runs completely non-portable code, regardless of the executive mechanism?

titaniumdecoy Sep 13th, 2006 8:36 PM

"The good" is that it's easy to compile the source code to formats that will run on other systems. It may not matter at present, but if a port becomes desirable in the future, the code won't need to be rewritten.

Besides, it's good practice; why not use deprecated functions if doing so will have no effect on the compiled executable?

DaWei Sep 13th, 2006 9:17 PM

I'm glad you 'splained that fer me. :beard:


All times are GMT -5. The time now is 10:19 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC