On Mon, May 24, 2010 at 11:23 AM, Bill Janssen <span dir="ltr"><<a href="mailto:janssen@parc.com">janssen@parc.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">C. Titus Brown <<a href="mailto:ctb@msu.edu">ctb@msu.edu</a>> wrote:<br>
<br>
> On Mon, May 24, 2010 at 07:46:32AM -0700, Bill Janssen wrote:<br>
> > I'm kind of surprised to see that the subprocess module doesn't have a<br>
> > documented function for calling to properly quote command-line<br>
> > arguments. Â Nor does it seem to do so automatically -- at least on Unix.<br>
><br>
> Bill, I may be about to reveal my profound ignorance here, but...<br>
><br>
> do you need to quote arguments passed as a list on UNIX? Â My impression<br>
> was that if shell=False, then it wasn't needed.<br>
<br>
</div>Yes, that's right. Â You need to quote them only if you are passing a<br>
whole command line to be evaluated as a shell, as with os.system() or<br>
shell=True and args a string with subprocess. Â I think subprocess gets<br>
all this more or less right.<br>
<br>
In my case, I was building up a command line to pass as a single string<br>
to subprocess, and needed a way to quote the args explicitly. Â That's<br>
why I went looking at this.<br clear="all"></blockquote><div> <br>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).<br>
</div></div><br>-- <br>Ian Bicking  |  <a href="http://blog.ianbicking.org">http://blog.ianbicking.org</a><br>