【发布时间】:2017-01-27 13:42:30
【问题描述】:
我正在尝试从 python 代码执行 10 个 python 脚本并在新的 shell 窗口中打开它们。
我的代码:
for i in range(10):
name_of_file = "myscript"+str(i)+".py"
cmd = "python " + name_of_file
os.system("gnome-terminal -e 'bash -c " + cmd + "'")
但是每个脚本文件都没有执行,我在新终端中只得到了python的实时解释器......
谢谢大家
【问题讨论】:
-
我建议使用 subprocess 模块,您可能对每个模块都有更多的控制权...
-
除了@fedepad,我想引用os.system的文档:“子进程模块提供了更强大的工具来生成新进程并检索它们的结果;使用该模块比使用更可取这个函数。”