Problems with Open-Source Downloads read and

Read all data from bash in QProcess

  • I am trying to make an app for LiveReload to watch certain folders.

    If i go to /var/www in my local console and type:

    @$ bundle exec guard@

    I get the following output:

    bq. 10:07:53 - INFO - Guard is using TerminalTitle to send notifications.
    10:07:53 - INFO - LiveReload is waiting for a browser to connect.
    10:07:53 - INFO - Guard is now watching at '/var/www/'
    [1] guard(main)>

    But if i go the Qt way
    @process = new QProcess(this);
    process->start("bundle exec guard");

            QByteArray result = process->readAll();
            qDebug() << result;@

    I get only this on my Qt console

    bq. [1] guard(main)>

    Is there a way to capture all the datas?

  • Seems like i got it

    @qDebug() << process->readAllStandardError() << process->readAll();@

    I thought readAll would also read the StandardError. Wonder why live reload sends these info to stderr tho

    Neways, thanks :)

  • More for future readers than the original poster -

    The documentation for the QProcess version of readAll() is a bit understated. The documentation for QProcess::setReadChannel() is informative:
    Sets the current read channel of the QProcess to the given channel. The current input channel is used by the functions read(), readAll() [...]

    If you think about it, reading every thing from standard output and standard error in a single function and returning them as a single string requires combining the two streams. Without indicators of what came from where, or at least an ordering policy, programmatic use would be very limited. Imagine a process that outputs 'aaaa...' on standard out, and 'bbbb...' on standard error. Should the combined output be "abab...", "aaaabbbb", or something else? What if 'a' on standard out is normal, and 'b' is exceptional?

Log in to reply