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=Falsedo, in contrast toshell=True? - I was under the impression that
subprocess.callandcheck_callandcheck_outputall 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=Truethat can't be done withshell=Falseand 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=TrueorFalseand why it doesn't matter