0

I am making a configuration tool for a machine. There is only one thing that is still bothering me.

I ssh to a IP adress and run some scripts on there. The output of these scripts are usefull information to understand if something is wrong with the machine. But to read the terminal output I need to watch the output in my visual studio code. I can't find a way to display this terminal output to something like a text box in PyQt5. Are there known solutions for this problem?

As a example of what I am trying to do:

import os
import sys
from PyQt5 import QtWidgets


def main():
    app = QtWidgets.QApplication(sys.argv)
    w = MyWindow()
    w.show()
    sys.exit(app.exec_())


class MyWindow(QtWidgets.QWidget):
    def __init__(self, *args):
        QtWidgets.QWidget.__init__(self, *args)

        # create objects
        label = QtWidgets.QLabel(self.tr("Enter command and press Return"))
        self.le = QtWidgets.QLineEdit()
        self.te = QtWidgets.QTextEdit()

        # layout
        layout = QtWidgets.QVBoxLayout(self)
        layout.addWidget(label)
        layout.addWidget(self.le)
        layout.addWidget(self.te)
        self.setLayout(layout)

        # create connection
        self.le.returnPressed.connect(self.run_command)

    def run_command(self):
        cmd = str(self.le.text())
        print(cmd)
        stdouterr = os.popen(cmd).read()
        self.te.setText(stdouterr)

if __name__ == "__main__":
    main()

If you run this code if gives you the option to run a command.

If you try 'ipconfig' it gives you the correct output.

When i try to run ssh root@10.23.1.11 it crashes. It seems that is cannot handle the connection that is made. So if there is anyone out there that knows a solution I would love to hear it.

didi00

didi00
  • 1
  • 1
  • i found this [question](https://stackoverflow.com/q/7114990/20589631) which already has a couple fully detailed answers on this issue. – ori raisfeld Jun 06 '23 at 14:34

0 Answers0