/*! Reads the data that the process has written to standard output. When new data is written to standard output, the class emits the signal readyReadStdout(). If there is no data to read, this function returns a QByteArray of size 0: it does not wait until there is something to read. \sa readyReadStdout() readLineStdout() readStderr() writeToStdin() */ QByteArray QProcess::readStdout() { if ( readStdoutCalled ) { return QByteArray(); } readStdoutCalled = TRUE; QMembuf *buf = membufStdout(); readStdoutCalled = FALSE; return buf->readAll(); }
/*! Reads the data that the process has written to standard output. When new data is written to standard output, the class emits the signal readyReadStdout(). If there is no data to read, this function returns a QByteArray of size 0: it does not wait until there is something to read. \sa readyReadStdout() readLineStdout() readStderr() writeToStdin() */ QByteArray Q3Process::readStdout() { if ( readStdoutCalled ) { return QByteArray(); } readStdoutCalled = true; Q3Membuf *buf = membufStdout(); readStdoutCalled = false; return buf->readAll(); }
/*! Reads a line of text from standard output, excluding any trailing newline or carriage return characters, and returns it. Returns QString::null if canReadLineStdout() returns FALSE. By default, the text is interpreted to be in Latin-1 encoding. If you need other codecs, you can set a different codec with QTextCodec::setCodecForCStrings(). \sa canReadLineStdout() readyReadStdout() readStdout() readLineStderr() */ QString QProcess::readLineStdout() { QByteArray a( 256 ); QMembuf *buf = membufStdout(); if ( !buf->scanNewline( &a ) ) { if ( !canReadLineStdout() ) return QString::null; if ( !buf->scanNewline( &a ) ) return QString( buf->readAll() ); } uint size = a.size(); buf->consumeBytes( size, 0 ); // get rid of terminating \n or \r\n if ( size>0 && a.at( size - 1 ) == '\n' ) { if ( size>1 && a.at( size - 2 ) == '\r' ) a.at( size - 2 ) = '\0'; else a.at( size - 1 ) = '\0'; } return QString( a ); }
/*! Reads a line of text from standard output, excluding any trailing newline or carriage return characters, and returns it. Returns an empty string if canReadLineStdout() returns false. By default, the text is interpreted to be in Latin-1 encoding. If you need other codecs, you can set a different codec with QTextCodec::setCodecForCStrings(). \sa canReadLineStdout() readyReadStdout() readStdout() readLineStderr() */ QString Q3Process::readLineStdout() { QByteArray a( 256 ); Q3Membuf *buf = membufStdout(); if ( !buf->scanNewline( &a ) ) { if ( !canReadLineStdout() ) return QString(); if ( !buf->scanNewline( &a ) ) return QLatin1String(buf->readAll()); } uint size = a.size(); buf->consumeBytes( size, 0 ); // get rid of terminating \n or \r\n if ( size>0 && a.at( size - 1 ) == '\n' ) { if ( size>1 && a.at( size - 2 ) == '\r' ) a.chop(2); else a.chop(1); } return QString(QString::fromLatin1(a.constData())); }