[python-win32] os.popen4 and spaces in the directory name
John Machin
sjmachin at lexicon.net
Sun Dec 4 21:55:33 CET 2005
Stephen Briley wrote:
> Hi all,
>
> I would like to run a program via the os.popen (or similar) commands.
> However, the path to the executable that I would like to run contains
> spaces (e.g. C:\program files\some directory\engine\theexe.exe). The
> python syntax that I am using is as follows:
>
> >>> os.popen4("C:\program files\some
> directory\engine\theexe.exe")[1].read()
>
> When I try to run it, I get the following message:
> "'C:\\program' is not recognized as an internal or external
> command,\noperable program or batch file.\n"
You have more than one problem. Firstly, as you have detected, the
Windows command interpreter's parser has to be steered away from the
spaces. You do this by using quotes (so-called double quotes, not
apostrophes aka single quotes).
Secondly, you need to either double your backslashes or use raw strings;
otherwise the \t in \theexe will be treated by Python as a TAB, not as
two characters \ and t, and similarly with \n \r \f etc etc.
So: r'"C:\program files\some directory\engine\theexe.exe"'
>
[snip]
>
> This time, it doesn't like the directory named "some directory". Is
> there any way around this? The command runs fine if I open up a Windows
> command prompt and specify the full directory path to the exe.
Thirdly, there seems to be some perceptual problem here. I don't see how
it could "run fine" if you type the same guff directly at the command
prompt. It's the same program processing your input. Example (Windows
XP, SP 2):
C:\junk>c:\program files\textpad 4\textpad.exe
'c:\program' is not recognized as an internal or external command,
operable program or batch file.
C:\junk>"c:\program files\textpad 4\textpad.exe"
[works OK]
> I am
> using python 2.4 on a Windows 2003 server. I am also running this
> command on Windows 2003 server.
>
Fourthly, this mailing list is for discussion of Mark Hammond's
python-win32 aka win32all package. news:com.lang.python is more
appropriate and would give you a wider audience.
Cheers,
John
More information about the Python-win32
mailing list