New submission from Charles Daffern:
Example code demonstrating the problem:
# {{{
import argparse
def try_args(*args):
parser = argparse.ArgumentParser()
parser.add_argument("-a")
print("Trying:", args)
try:
print(parser.parse_args(args))
Charles Daffern added the comment:
>To be sure that it is existing program, you can use shutil.which()
I'd like to clear this up a little because this is worded as if
shutil.which()'s success implies that the shell will not fail.
Here is the setup to demonstrate:
>>> im
Charles Daffern added the comment:
In that case, should the documentation specify that shlex.quote is unsuitable
for quoting command names?
--
___
Python tracker
<http://bugs.python.org/issue26
Charles Daffern added the comment:
It's definitely a corner case (in argv[0] position + is keyword), but here's an
example:
>>> import subprocess
>>> import shlex
>>> subprocess.call(shlex.quote("done"), shell=True)
/bin/sh: 1: Syntax error: &
New submission from Charles Daffern:
The shlex.quote and pipes.quote functions do not quote shell keywords.
Example shell keywords: done, time, coproc, while
Presumably the intent of the quote functions is to prevent the resulting string
from altering the syntax of the script it is inserted