The difference between shell=True
and shell=False
on Unix-like systems is that the shell takes care of breaking up the command line for exec
, whereas if you don't have a shell, you have to do that yourself.
The shell offers no benefits here, so you can safely drop it.
subprocess.call(["sudo", "systemctl", "restart", "nginx"])
So in the general case anything which looks like
subprocess.something("blah 'blah' \"blah\"", shell=True)
needs to be converted into a list without shell quoting to run it without shell=True
:
subprocess.something(['blah', 'blah', "blah"])
and of course anything which is specific to the shell (redirection, pipelines, globbing, etc) will need to be replaced with native Python code.
More details at Actual meaning of 'shell=True' in subprocess and Running Bash commands in Python
If your original code didn't work, this also probably won't work, though.