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. QProcess std & err read
Forum Updated to NodeBB v4.3 + New Features

QProcess std & err read

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 4.1k 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.
  • S Offline
    S Offline
    saaleb
    wrote on last edited by
    #1

    Hi,

    I have such code impement my own class derived from QPRocess:

    @ModProcess::ModProcess(QObject *parent, Settings::Module const& pModule) :
    QProcess(parent)
    {

    connect( this, SIGNAL(finished(int)), this, SLOT(onProcFinished()));
    connect( this, SIGNAL(error(QProcess::ProcessError)), SLOT(onProcError(QProcess::ProcessError)));
    connect( this, SIGNAL(stateChanged(QProcess::ProcessState)), SLOT(onProcStateChanged(QProcess::ProcessState)));
    
    connect( this, SIGNAL(readyReadStandardOutput()), SLOT(onProcReadyReadStdOut()));
    connect( this, SIGNAL(readyReadStandardError()), SLOT(onProcReadyReadStdErr()));
    

    }

    void ModProcess::onProcReadyReadStdOut()
    {

    QList<QByteArray> pOut = this->readAllStandardOutput().split( '\n' );
    foreach( QByteArray pLine, pOut ) {
        pLine.replace( '\r', QByteArray() );
        if( pLine.size() <= 0 ) continue;
        logWrite( LL_INFO, "pid (%d) [stdout]: %s", this->pid(), pLine.constData() );
    }
    

    }

    void ModProcess::onProcReadyReadStdErr()
    {

    QList<QByteArray> pOut = this->readAllStandardError().split( '\n' );
    foreach( QByteArray pLine, pOut ) {
        pLine.replace( '\r', QByteArray() );
        if( pLine.size() <= 0 ) continue;
        logWrite( LL_INFO, "pid (%d) [stderr]: %s", this->pid(), pLine.constData() );
    }
    

    }@

    all working fine except std & errr reading, when I got process output by appropriate signal, I have empty
    string on it. On stderr behavior is same.

    [2013/05/07 01:02:21] <+000>: pid (10660) [stdout]: (null)
    [2013/05/07 01:02:21] <+000>: pid (10660) [stdout]: (null)

    when I set QProcess out to file, output is present.

    I will be very thankful for any info or ideas why its happen.

    Thanks!

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      Hi,

      for debug purpose you could print all contents of readAllStandardError() and readAllStandardOutput() return value.

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0
      • S Offline
        S Offline
        saaleb
        wrote on last edited by
        #3

        Hi,

        I already tried this, but readAllStandardError() and readAllStandardOutput returns empty QByteArray.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mcosta
          wrote on last edited by
          #4

          Ok,

          and what does it mean "when I set QProcess out to file, output is present." ?

          Once your problem is solved don't forget to:

          • Mark the thread as SOLVED using the Topic Tool menu
          • Vote up the answer(s) that helped you to solve the issue

          You can embed images using (http://imgur.com/) or (http://postimage.org/)

          1 Reply Last reply
          0
          • S Offline
            S Offline
            saaleb
            wrote on last edited by
            #5

            QProcess have QProcess::setStandardErrorFile() and QProcess::setStandardOutputFile() methods that allow to set stderr & stdout of process output to odinary file.

            In this case I see output from process stdout & stderr.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mcosta
              wrote on last edited by
              #6

              Hi,

              QProcess::setStandardErrorFile() and QProcess::setStandardOutputFile() doc says

              bq. When the redirection is in place, the standard error read channel is closed: reading from it using read() will always fail, as will readAllStandardError().

              but readyReadStandardOutput and readyReadStandardError says

              bq. It is emitted regardless of the current read channel.

              It's important to check what is the read channel of QProcess

              Once your problem is solved don't forget to:

              • Mark the thread as SOLVED using the Topic Tool menu
              • Vote up the answer(s) that helped you to solve the issue

              You can embed images using (http://imgur.com/) or (http://postimage.org/)

              1 Reply Last reply
              0
              • S Offline
                S Offline
                saaleb
                wrote on last edited by
                #7

                When I used readyReadStandardOutput () I didn't used file redirection. just turn it on for some moments to ensure I have output at all.

                May be something debug feature in QT can be turned to helps problem recognizing?

                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