How does subprocess.call() work with shell=False?

Viewed 8895

I am using Python's subprocess module to call some Linux command line functions. The documentation explains the shell=True argument as

If shell is True, the specified command will be executed through the shell

There are two examples, which seem the same to me from a descriptive viewpoint (i.e. both of them call some command-line command), but one of them uses shell=True and the other does not

>>> subprocess.call(["ls", "-l"])
0

>>> subprocess.call("exit 1", shell=True)
1

My question is:

  • What does running the command with shell=False do, in contrast to shell=True?
  • I was under the impression that subprocess.call and check_call and check_output all must execute the argument through the shell. In other words, how can it possibly not execute the argument through the shell?

It would also be helpful to get some examples of:

  • Things that can be done with shell=True that can't be done with shell=False and why they can't be done.
  • Vice versa (although it seems that there are no such examples)
  • Things for which it does not matter whether shell=True or False and why it doesn't matter
2 Answers
Related