execv putting quotes around arguments
Mike Vieths
foeclan at yahoo.com
Fri Feb 6 11:36:03 EST 2004
I'm running into a problem when I try to run commands with os.execv. It
seems to be putting quotation marks around each element of the list
passed as its second argument. This is fine for the most part, but if
the argument has a space in it, getopt (in the command being called)
will read the entire quoted string as the argument and generally fail.
Here's an example:
Python 2.2.2 (#1, Jan 30 2003, 21:26:22)
[GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-112)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> arg0='/bin/ls'
>>> arg1='-l foo'
>>> args=[arg0]+[arg1]
>>> os.execv(arg0, args)
/bin/ls: invalid option --
Try `/bin/ls --help' for more information.
This can be worked around by breaking '-l foo' into two seperate
elements ('-l' and 'foo'), but that's not always intuitive. Anyone know
why those quotes are there, and if there's a way to make them go away?
I'm stuck with execv, since this is part of a larger project for which
I'm creating a module, and modifying that portion to use os.popen,
os.system, or something similar isn't an option.
Mike Vieths
More information about the Python-list
mailing list