Elie khalifeh Elie khalifeh - 4 months ago 12
Bash Question

Execute a python script using Popen with shell=False

I would like to know if it's possible to execute this command

cmd = "gnome-terminal -e 'python /path/to/file.py'"

p = subprocess.Popen(cmd,shell=True)

but with shell=False

I tried to run this command

p = subprocess.Popen(["gnome-terminal","-e","python","/path/to/file.py"],shell = False)

but it's not working:

Thank you!


As it is you're passing the command to gnome-terminal, not python.

p = subprocess.Popen(["gnome-terminal","-e","python /path/to/file.py"],shell = False)