使用Python,我想在新的终端窗口中启动一个进程,因为这样可以向用户显示正在发生的事情,因为涉及多个进程.
我试过做:
>>> import subprocess
>>> subprocess.Popen(['gnome-terminal'])
这按照我的意愿工作,打开一个新窗口.
但是如何将参数传递给它呢?就像,当终端启动时,我希望它说,运行ls.但是这个:
>>> subprocess.Popen(['gnome-terminal', 'ls'])
这又有效,但ls命令不起作用:一个空白终端窗口启动.
所以我的问题是,如何使用指定的命令启动终端窗口,以便在窗口打开时运行该命令.
PS:我的目标只是Linux.
解决方法:
$gnome-terminal --help-all
...
-e, --command Execute the argument to this option inside the terminal
...
如果您希望窗口保持打开状态,那么您需要运行一个shell或命令,以使其保持打开状态.
标签:python,subprocess,terminal
来源: https://codeday.me/bug/20190721/1496894.html