How to execute an EXE via os.system() with spaces in the directory name?

sdb1031 at gmail.com sdb1031 at gmail.com
Sun Dec 4 04:16:10 CET 2005


I am trying to run an exe within a python script, but I'm having
trouble with spaces in the directory name.

The following example will display the usage statement of the program,
so I know that the space in the path to the exe is being handled
correctly and that the program was executed.

CMD= r'"C:\program files\some directory\engine\theexe.exe"'
os.system(CMD)

But the required argument for the exe require a path to a file to be
specified.  When I try to run the following, os.system(CMD2)
CMD2= r'"C:\program files\some directory\engine\theexe.exe" "C:\program
files\some directory\engine\file.txt"'

I get this error:
Unable to open file C:\Program

So, it looks to me like the space in the path for the argument is
causing it to fail.  Does anyone have any suggestions that could help
me out?
Thanks,
Steve




More information about the Python-list mailing list