qt - 如何从 QProcess 获取 STDOUT?

标签 qt process stdout qprocess

我以为我将使用以下代码从 QProcess 获取输出:

// Start the process
process.start(tr("php-cgi www/test.php"),QIODevice::ReadWrite);

// Wait for it to start
if(!process.waitForStarted())
    return 0;

// Continue reading the data until EOF reached
QByteArray data;

while(process.waitForReadyRead())
    data.append(process.readAll());

// Output the data
qDebug(data.data());
qDebug("Done!");

我期望看到程序的输出打印到调试控制台,但我看到的是:

Done!



我知道:
  • 程序启动正常,因为打印了最后的消息。
  • 该程序会打印输出,因为在终端中运行完全相同的命令会按预期生成一长串文本。

  • 我在这里做错了什么?

    最佳答案

    在开始流程调用之前:

    process.setProcessChannelMode(QProcess::MergedChannels);
    

    它会导致将所有内容(甚至 STDERR 输出)打印到 STDOUT 输出。

    关于qt - 如何从 QProcess 获取 STDOUT?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3852587/

    相关文章:

    unix - 错误: Unbound module Unix in Ocaml

    python - PyQt5 - 类型错误 : signal has 0 argument(s) but 1 provided

    linux - 动态地逐行解析程序输出

    c - 如何获取linux内核当前进程的一些信息

    c - 无法使用 popen 函数读取命令输出

    c - 如何读取 PowerShell 标准输出

    c++ - 加载 DLL 是否会动态协调其 stderr 到主应用程序?如果是这样,那么如何......?

    qt - 我只是无法让 QTcpServer 工作(从未调用过 newConnection)

    c++ - 使用 QT 的菜单栏应用程序

    c++ - 我如何在QT中制作横幅,例如CNN/FOX的新闻横幅?