popen eating quotes?

Bryan belred1 at yahoo.com
Sun Aug 3 19:22:19 EDT 2003


"Jeff Epler" <jepler at unpythonic.net> wrote in message
news:mailman.1059942307.4825.python-list at python.org...
> This has been discussed before.  One such thread that I participated in
> was
>
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=0000161b%40bossar.com.pl&rnum=1&prev=/groups%3Fq%3Dshell%2Bquoting%2Bnt%2Bgroup:comp.lang.python%26hl%3Den%26lr%3D%26ie%3DUTF-8%26selm%3D0000161b%2540bossar.com.pl%26rnum%3D1%26filter%3D0
> [apologies for the long URL, I don't know how to get a good memorable
> URL for a google groups search]
>
> This really is a cesspool on Windows, and the fault isn't Python's.
> Python is just calling the Windows functions, which insist on behaving
> badly compared to the Unix behavior.
>
> unix bigot'ly yours,
> jeff
>

thanks for the link, but it didn't help me solve my problem. i just read
many articles posted about popen and windows and there seems to be a
solution to this problem.  i need to pass a path to a program using popen so
i can capture the output.  since the path and/or file name can have spaces
in it, i need to quote it.   what's the way to get around this issue?  i saw
it mentioned in several places to try win32pipe.popen, but it had the same
problem as os.popen.  so, is this something that cannot be done in python at
all with no work-around?  is there another way besides using os.system or
os.popen?

>>> import os
>>> def run_args(arg):
...  i, o = os.popen4('"c:/program files/test/args.bat" -vv %s' % arg)
...  print o.read()
...
>>> run_args('"this is a very long path with spaces"')
'c:/program' is not recognized as an internal or external command,
operable program or batch file.

thanks,

bryan






More information about the Python-list mailing list