Debugging automatic quotation in subprocess.Popen()
Chris Angelico
rosuav at gmail.com
Fri Oct 7 17:27:57 EDT 2022
On Sat, 8 Oct 2022 at 08:24, <c.buhtz at posteo.jp> wrote:
>
> Hello,
>
> I need to improve my understanding about how subprocess.Popen() does
> quote arguments. I have special case here.
>
> Simple example:
> Popen(['ls', '-l']) results on a shell in "ls -l" without quotation.
>
> Quotes are added if they are needed:
> Popen(['ls', 'folder with blank']) results on a shell in
> "ls 'folder with blank'".
>
> Am I right so far with the basics?
>
> Is there a way to be sure and to debug how Popen() give it to the shell?
That's kinda looking at it backwards; the shell first splits the
command into a list of arguments, and then runs it. Python has a
module that is capable of doing similar sorts of work:
https://docs.python.org/3/library/shlex.html
That may be helpful if you want to give the user something to copy and paste.
ChrisA
More information about the Python-list
mailing list