使用参数启动 gnome-terminal [英] Starting gnome-terminal with arguments

查看:55
本文介绍了使用参数启动 gnome-terminal的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Python ,我想在一个新的终端窗口中启动一个进程,因为这样可以向用户展示正在发生的事情,而且涉及的进程不止一个.

我尝试过:

<预><代码>>>>导入子流程>>>subprocess.Popen(['gnome-terminal'])<subprocess.Popen 对象在 0xb76a49ac>

这如我所愿,打开了一个新窗口.

但是我该如何传递参数呢?就像,当终端启动时,我想让它说,运行 ls.但是这个:

<预><代码>>>>subprocess.Popen(['gnome-terminal', 'ls'])<subprocess.Popen 对象在 0xb76a706c>

这再次起作用,但 ls 命令不起作用:一个空白的终端窗口启动.

所以我的问题是,如何使用指定的命令启动终端窗口,以便在窗口打开时运行该命令.

PS:我的目标是 Linux.

解决方案

$ gnome-terminal --help-all...-e, --command 在终端内执行此选项的参数...

如果您希望窗口保持打开,那么您需要运行一个 shell 或命令以使其在之后保持打开状态.

Using Python , I would like to start a process in a new terminal window, because so as to show the user what is happening and since there are more than one processes involved.

I tried doing:

>>> import subprocess
>>> subprocess.Popen(['gnome-terminal'])
<subprocess.Popen object at 0xb76a49ac>

and this works as I want, a new window is opened.

But how do I pass arguments to this? Like, when the terminal starts, I want it to say, run ls. But this:

>>> subprocess.Popen(['gnome-terminal', 'ls'])
<subprocess.Popen object at 0xb76a706c>

This again works, but the ls command doesn't: a blank terminal window starts.

So my question is, how do I start the terminal window with a command specified, so that the command runs when the window opens.

PS: I am targetting only Linux.

解决方案

$ gnome-terminal --help-all

 ...

  -e, --command                   Execute the argument to this option inside the terminal

 ...

If you want the window to stay open then you'll need to run a shell or command that keeps it open afterwards.

这篇关于使用参数启动 gnome-terminal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆