start/run 一个外部可执行文件并查看其输出日志
To start/run an external executable and see its output logs
我从我的 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 exist\n";
}
我的 agent.exe
运行 没问题 QProcess *
,但问题是我看不到它的输出日志。有没有办法查看它的日志?
您可以将 QProcess
的信号 readyReadStandardOutput()
连接到您应用中的插槽并使用函数 QProcess::readAllStandardOutput()
您将获得 QByteArray
形式的数据,您可以要么保存在 QFile
中,要么在 QTextBrowser
中显示给用户
我从我的 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 exist\n";
}
我的 agent.exe
运行 没问题 QProcess *
,但问题是我看不到它的输出日志。有没有办法查看它的日志?
您可以将 QProcess
的信号 readyReadStandardOutput()
连接到您应用中的插槽并使用函数 QProcess::readAllStandardOutput()
您将获得 QByteArray
形式的数据,您可以要么保存在 QFile
中,要么在 QTextBrowser