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,
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