In most answers (I found) to the question "How to run an external command" I see something along the lines
If you want to run
ls -l
you need to usesubprocess.call(["ls", "-l"])
What I normally do when I know what I will be running is to call subprocess.call('ls -l'.split(' '))
to have visually the command line in one piece (it is usually a variable).
Is there anything inherently wrong with using split()
as opposed to building the list manually (again, when the command is known). Or are these answers crafted to explicitly show that a list is needed?
I tried to find some drawbacks (multiple spaces, escaped spaces, ...) but I do not see where that approach could go wrong?
Note: this question is specifically about the robustness of splitting on spaces, not the security issues or other (very important) considerations as such.