我如何 运行 'screen' 不连接到终端,以便我可以在 C++ (qt) 应用程序中捕获输出?

How can I run 'screen' without it being attached to a terminal so that I can capture the output in a C++ (qt) app?

我目前正在 Mac OS 终端中使用命令

显示我的嵌入式设备的串行输出
screen /dev/tty.SLAB_USBtoUART 115200

我不想在终端中显示输出,而是希望能够在我的 C++ (qt) 应用程序中逐行读取它,以便我可以处理它并在 GUI 中显示它。

我试图为 运行 上面的屏幕命令创建一个 QProcess 对象,但是屏幕失败,显示 "Must be connected to a terminal"。

有什么方法可以 "fake" 连接到终端,以便 QProcess 能够成功 运行 屏幕命令?我不需要输入任何命令,我只需要捕获嵌入式设备正在写入的输出。

您可以使用 boost serial port to read the incoming data. Be aware that this will have to be done in a thread or using Qt Concurrent. From this thread you can send signals that connected to the correct slots of your data display will take the data and display it. However, Qt also provides a serial port class that you can use: QSerialPort. I would recomend using QTextEdit as your display widget and QTextEdit::append 作为您的广告位。