Python: Subprocess call with shell = False does not work


I am using Python script to invoke a Java virtual machine. The following command works:["./rvm"], shell=False)  # works["./rvm xyz"], shell=True) # works

But,["./rvm xyz"], shell=False) # not working

does not work. Python documentation advices to avoid shell=True.

You need to split the commands into separate strings:["./rvm", "xyz"], shell=False)

A string will work when shell=True but you need a list of args when shell=False

The shlex module is useful more so for more complicated commands and dealing with input but good to learn about:

import shlex

cmd = "python", shell=False)

shlex tut