popen eating quotes?

Bryan belred1 at yahoo.com
Sun Aug 3 11:56:26 EDT 2003


i have a batch file that contains these two lines:

-- args.bat

echo %1
echo %2


when i run args.bat from the command line it works correctly... notice that
abc has quotes in the first example and not in the second.

C:\Temp>"c:\program files\test\args" -vv abc
C:\Temp>echo -vv
-vv
C:\Temp>echo abc
abc

C:\Temp>"c:\program files\test\args" -vv "abc"
C:\Temp>echo -vv
-vv
C:\Temp>echo "abc"
"abc"


from python, i'm having trouble getting the quotes around abc to work

>>> import os
>>> def run_args(arg):
...  i, o = os.popen4('"c:/program files/test/args.bat" -vv %s' % arg)
...  print o.read()
...
>>> run_args('abc')
C:\python\python23\lib\site-packages>echo -vv
-vv
C:\python\python23\lib\site-packages>echo abc
abc

>>> run_args('"abc"')
'c:/program' is not recognized as an internal or external command,
operable program or batch file.


what is going on here?  why does "abc" effect the uoted program name.  does
anyone know how to fix this?   how to pass a quoted arguments through to
popen?  i need to do this because in my real code, i'm passing paths as
arguments and need them quoted.

i'm using python 2.3 on winxp.

thanks,

bryan






More information about the Python-list mailing list