QProcess std & err read



  • 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!



  • Hi,

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



  • Hi,

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



  • Ok,

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



  • 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.



  • 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



  • 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?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.