How to create the command list argument

suggest change

With 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']

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents