使 xterm 窗口打开,直到用户将其关闭

发布于 2024-10-02 11:01:05 字数 694 浏览 2 评论 0原文

如何调用一个永久的xterm窗口并且仅当用户关闭它时它才关闭?

这是将重现此问题的代码

import os
from PyQt4 import QtCore, QtGui
from main import Ui_MainWindow

class Main(QtGui.QMainWindow):
    def __init__(self, parent=None):
    QtGui.QWidget.__init__(self, parent)
    self.ui = Ui_MainWindow()
    self.ui.setupUi(self)

        QtCore.QObject.connect(self.ui.pushID, QtCore.SIGNAL('clicked()'), self.showid)

    def showid(self):
        process = subprocess.Popen(['lsusb'], shell=False, stdout=subprocess.PIPE)
        process.communicate()[0]

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    main = Main()
    main.show()
    sys.exit(app.exec_())

有什么建议吗?

how to call a permanent xterm window and it's closed only when user close it?

here's the code that will recreate this problem

import os
from PyQt4 import QtCore, QtGui
from main import Ui_MainWindow

class Main(QtGui.QMainWindow):
    def __init__(self, parent=None):
    QtGui.QWidget.__init__(self, parent)
    self.ui = Ui_MainWindow()
    self.ui.setupUi(self)

        QtCore.QObject.connect(self.ui.pushID, QtCore.SIGNAL('clicked()'), self.showid)

    def showid(self):
        process = subprocess.Popen(['lsusb'], shell=False, stdout=subprocess.PIPE)
        process.communicate()[0]

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    main = Main()
    main.show()
    sys.exit(app.exec_())

any suggestion?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

提笔落墨 2024-10-09 11:01:05

不要使用os.system。使用 subprocess

>>> import subprocess
>>> subprocess.Popen(['xterm'])

尽管您最好从 subprocess 获取输出,但无需涉及 xterm。

>>> process = subprocess.Popen(['lsusb'], shell=False, stdout=subprocess.PIPE)
>>> process.communicate()[0]

请注意 shell=False。这是读取 lsusb 命令输出的方式。

如果您正在寻找有关 subprocess 的教程,此< /a> 很好。

Don't use os.system. Use subprocess

>>> import subprocess
>>> subprocess.Popen(['xterm'])

Though you are better getting the output from subprocess without involving xterm.

>>> process = subprocess.Popen(['lsusb'], shell=False, stdout=subprocess.PIPE)
>>> process.communicate()[0]

Note that shell=False. This is how you would read the output from the lsusb command.

If you are looking for a tutorial on subprocess, this is good.

时光是把杀猪刀 2024-10-09 11:01:05

这是一个老问题,但在这种情况下OP想要的是:

import subprocess
subprocess.Popen(['xterm','-hold','-title','Usb Devices Available','-geometry','80x30+2000+0','-e','lsusb'])

-hold(执行后保持xterm窗口打开)
-title(xterm 窗口中的名称) 如果没有 -title,窗口将采用执行的命令的名称,在本例中为 lsusb
-几何(终端宽度、高度、水平位置、垂直位置)
-e(此后的所有内容都是要运行的命令)
lsusb(我希望在 xterm 中运行的命令)

It's an old question but what the OP wanted in this case was:

import subprocess
subprocess.Popen(['xterm','-hold','-title','Usb Devices Available','-geometry','80x30+2000+0','-e','lsusb'])

-hold (keep the xterm window open once it has executed)
-title (the name in the xterm window) without -title the window takes the name of the command executed, in this case lsusb
-geometry (terminal width, height,horizontal position, vertical position)
-e (everything after this is the command to run)
lsusb (the command I wish to run in xterm)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文