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

Vijay L liyer.vijay at gmail.com
Sat Dec 3 22:52:19 EST 2005


I don't have any problems with spaces in the folders.

just for debugging, you could probably try os.system(CMD.replace("\\", "/")

On 3 Dec 2005 19:16:10 -0800, sdb1031 at gmail.com <sdb1031 at gmail.com> wrote:
> 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
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list