Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python subprocess, usage of the shell argument

Looking at http://docs.python.org/2/library/subprocess.html#frequently-used-arguments I made the assumption that unless you use shell=True, there is no ability to use rm,cp,mv etc. Maybe the documentation is out-of-date as they are feeding the call method with a string, where it should be a list. But using shell=False certainly doesn't prevent the usage of said shell commands.

shell=False disables all shell based features

After looking at subprocess.py, I can see that all that argument does is add ["/bin/sh", "-c"] to the start of the argument string.

Can someone clarify this for me?

like image 823
joedborg Avatar asked Nov 08 '12 11:11

joedborg


1 Answers

The shell features they are talking about are things like | pipes, * globs and other wildcards, stdout/stderr redirects with > or 2>, <(process substitution) etc. They are not talking about other commands/programs such as mv, grep, etc.

like image 193
wim Avatar answered Oct 02 '22 06:10

wim