I use QtDesigner and pyqt4 for design my application. I want to show os.system() function results in textEdit! here is my code:
def aiaa(self):
import os
ss = os.system("systemctl status tor.service")
self.textEdit.setText(str(ss))
def setupUi(self, MainWindow):
self.textEdit = QtGui.QTextEdit(self.centralwidget)
self.textEdit.setGeometry(QtCore.QRect(40, 10, 351, 201))
self.textEdit.setObjectName(_fromUtf8("textEdit"))
self.pushButton = QtGui.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(170, 250, 94, 32))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.pushButton.clicked.connect(self.aiaa)
but its show result in terminal not in textEdit. Thanks...
The reason your example won't work is because
os.system
returns the exit code of the command, rather than its output (which is just printed on stdout). There are other questions which give some standard python solutions for this, but since you are using PyQt. I thought I'd show the Qt way of doing things instead.Below is a demo script that uses a
QProcess
to run commands. Signals from the process are connected to some slots which can then display the output from stdout and stderr whenever they become available: