Elie khalifeh Elie khalifeh - 1 year ago 77
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!

Answer Source

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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download