How to create the command list argument
suggest changeWith shell=False, the default, pass the command as a list. There is no shell_mode parameter.
The rules to create the list are not always straightforward to follow, especially with complex commands. Fortunately, there is a very helpful tool that allows doing that: shlex. The easiest way of creating the list to be used as command is the following, where command_used_in_the_shell is that command string:
import shlex
cmd_to_subprocess = shlex.split(command_used_in_the_shell)
A simple example:
import shlex
print(shlex.split('ls --color -l -t -r'))
['ls', '--color', '-l', '-t', '-r']
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents