启动/运行外部可执行文件并查看其输出日志

To start/run an external executable and see its output logs

本文关键字:输出 日志 运行 外部 可执行文件 启动      更新时间:2023-10-16

我从我的Qt应用程序中运行一个名为agent.exe的外部可执行文件,如下所示:

// header
QProcess *m_agent;
// source
m_agent = new QProcess(this);
QString agentPath = QCoreApplication::applicationDirPath() + "/agent.exe";
if (QFileInfo::exists(agentPath) && QFileInfo(agentPath).isFile()) {
    m_agent->start(agentPath);
} else {
    qDebug() << __func__ << "Executable does NOT existn";
}

我的agent.exeQProcess *运行良好,但问题是我看不到它的输出日志。有没有办法查看其日志?

您可以将

QProcess的信号readyReadStandardOutput()连接到应用程序中的插槽,并使用该功能QProcess::readAllStandardOutput()您将以QByteArray形式获取数据,您可以将其保存在QFile中或在QTextBrowser中向用户显示