使用Popen执行python脚本,shell = False

时间:2016-06-10 15:50:56

标签: python shell subprocess popen gnome

我想知道是否可以执行此命令

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

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

但是shell = False

我试图运行此命令

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

但它不起作用:

谢谢!

1 个答案:

答案 0 :(得分:2)

因为您将命令传递给gnome-terminal,而不是python

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