Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Read all data from bash in QProcess
Forum Updated to NodeBB v4.3 + New Features

Read all data from bash in QProcess

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nayar
    wrote on last edited by
    #1

    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->setWorkingDirectory(location());
    process->start("bundle exec guard");

            process->waitForStarted();
            process->waitForReadyRead();
    
            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?

    1 Reply Last reply
    0
    • N Offline
      N Offline
      Nayar
      wrote on last edited by
      #2

      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 :)

      1 Reply Last reply
      0
      • jeremy_kJ Offline
        jeremy_kJ Offline
        jeremy_k
        wrote on last edited by
        #3

        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?

        Asking a question about code? http://eel.is/iso-c++/testcase/

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved