代码之家  ›  专栏  ›  技术社区  ›  Megidd

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

  •  0
  • Megidd  · 技术社区  · 6 年前

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

    // 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";
    }
    

    我的 代理程序 运行良好 QProcess * 但问题是我看不到它的输出日志。有没有办法查看它的日志?

    1 回复  |  直到 6 年前
        1
  •  2
  •   Gurushant GeneCode    6 年前

    你可以接通信号 readyReadStandardOutput() 属于 QProcess 到应用程序中的一个插槽并使用该功能 QProcess::readAllStandardOutput() 你将得到数据 QByteArray 可以保存在 QFile 或向用户显示 QTextBrowser