[stdlib-sig] quoting arguments for command-line evaluation
ianb at colorstudy.com
Mon May 24 19:13:32 CEST 2010
On Mon, May 24, 2010 at 11:23 AM, Bill Janssen <janssen at parc.com> wrote:
> C. Titus Brown <ctb at msu.edu> wrote:
> > On Mon, May 24, 2010 at 07:46:32AM -0700, Bill Janssen wrote:
> > > I'm kind of surprised to see that the subprocess module doesn't have a
> > > documented function for calling to properly quote command-line
> > > arguments. Nor does it seem to do so automatically -- at least on
> > Bill, I may be about to reveal my profound ignorance here, but...
> > do you need to quote arguments passed as a list on UNIX? My impression
> > was that if shell=False, then it wasn't needed.
> Yes, that's right. You need to quote them only if you are passing a
> whole command line to be evaluated as a shell, as with os.system() or
> shell=True and args a string with subprocess. I think subprocess gets
> all this more or less right.
> In my case, I was building up a command line to pass as a single string
> to subprocess, and needed a way to quote the args explicitly. That's
> why I went looking at this.
I've had to do this sort of thing for similar reasons, like calling remote
ssh commands, where a shell command is embedded in a positional argument. I
implemented my own thing, but the way pipes.quote works would have been
nicer (the implementation could use a couple regexes instead of iterating
over strings though).
Ian Bicking | http://blog.ianbicking.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the stdlib-sig