Sanitising arguments to shell commands (was: Waiting for a subprocess to exit)

Chris Rebert clp2 at rebertia.com
Fri Aug 21 05:19:13 EDT 2009


On Fri, Aug 21, 2009 at 2:08 AM, Ben Finney<ben+python at benfinney.id.au> wrote:
<snip>
> How can I take a string that is intended to be part of a command line,
> representing multiple arguments and the shell's own escape characters as
> in the above example, and end up with a sane command argument list for
> ‘subprocess.Popen’?

http://docs.python.org/library/shlex.html

module shlex — Simple lexical analysis
New in version 1.5.2.
"The shlex class makes it easy to write lexical analyzers for simple
syntaxes resembling that of the Unix shell."

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list