When shell
is True, the first argument is appended to ["/bin/sh", "-c"]
. If that argument is a list, the resulting list is
["/bin/sh", "-c", "ls", "-al"]
That is, only ls
, not ls -al
is used as the argument to the -c
option. -al
is used as the first argument the shell itself, not ls
.
When using shell=True
, you generally just want to pass a single string and let the shell split it according the shell’s normal word-splitting rules.
# Produces ["/bin/sh", "-c", "ls -al"]
subprocess.call("ls -al", shell=True)
In your case, it doesn’t see like you need to use shell=True
at all.