win32+popen4

Jeff Shannon jeff at ccvcorp.com
Fri Mar 1 16:18:14 EST 2002


Robert Amesz wrote:

> On Win98 I've found I had to quote *and* escape the quote characters,
> and - sometimes - backslashes too. I'm not sure if this is also the
> case on Win2000, but it's worth a try. This would yield something like:
>
> '\\"c:\\\\program files\\\\dimbo\\\\bongo.exe\\\\" \\"c:\\\\program
> files\\\\dumbo\\\\my file.dat\\"'
>
> Horrible, I know.

This is why raw strings exist.

>>> mystring1 = '\\"c:\\\\program files\\\\dimbo\\\\bongo.exe\\\\"
\\"c:\\\\program files\\\\dumbo\\\\my file.dat\\"'
>>> print mystring1
\"c:\\program files\\dimbo\\bongo.exe\\" \"c:\\program files\\dumbo\\my
file.dat\"
>>> mystring2 = r'\"c:\\program files\\dimbo\\bongo.exe\" \"c:\\program
files\\dumbo\\my file.dat\"'
>>> # note!     ^ the 'r' here!
>>> print mystring2
\"c:\\program files\\dimbo\\bongo.exe\" \"c:\\program files\\dumbo\\my
file.dat\"
>>>

Note that you've got an extra backslash in your version -- you want a
single escaped double quote after 'bongo.exe', not an escaped backslash
followed by an unescaped double quote.  Raw strings will save you much
pain.

Jeff Shannon
Technician/Programmer
Credit International





More information about the Python-list mailing list