Utils: Fix readDataFromProcess()

The internal handling of output gets in the way when trying
to read output from a process synchronously.
Make usage of the internal one instead of relying on the
original output handling.

Fixes: QTCREATORBUG-25958
Change-Id: Ie96b5e8d17799a613ff15a52a23a8bdc31cb2939
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Stenger
2021-07-29 15:35:53 +02:00
parent 20641caa3a
commit fe65998351
2 changed files with 4 additions and 4 deletions

View File

@@ -540,15 +540,15 @@ bool QtcProcess::readDataFromProcess(int timeoutS,
finished = waitForFinished(timeoutS > 0 ? timeoutS * 1000 : -1) finished = waitForFinished(timeoutS > 0 ? timeoutS * 1000 : -1)
|| state() == QProcess::NotRunning; || state() == QProcess::NotRunning;
// First check 'stdout' // First check 'stdout'
if (d->m_process->bytesAvailable()) { // applies to readChannel() only const QByteArray newStdOut = readAllStandardOutput();
if (!newStdOut.isEmpty()) {
hasData = true; hasData = true;
const QByteArray newStdOut = d->m_process->readAllStandardOutput();
if (stdOut) if (stdOut)
stdOut->append(newStdOut); stdOut->append(newStdOut);
} }
// Check 'stderr' separately. This is a special handling // Check 'stderr' separately. This is a special handling
// for 'git pull' and the like which prints its progress on stderr. // for 'git pull' and the like which prints its progress on stderr.
const QByteArray newStdErr = d->m_process->readAllStandardError(); const QByteArray newStdErr = readAllStandardError();
if (!newStdErr.isEmpty()) { if (!newStdErr.isEmpty()) {
hasData = true; hasData = true;
if (stdErr) if (stdErr)

View File

@@ -161,7 +161,7 @@ static QMap<qint64, QString> getLocalProcessDataUsingPs(const QString &column)
psProcess.start(); psProcess.start();
if (psProcess.waitForStarted()) { if (psProcess.waitForStarted()) {
QByteArray output; QByteArray output;
if (psProcess.readDataFromProcess(30000, &output, nullptr, false)) { if (psProcess.readDataFromProcess(30, &output, nullptr, false)) {
// Split "457 /Users/foo.app arg1 arg2" // Split "457 /Users/foo.app arg1 arg2"
const QStringList lines = QString::fromLocal8Bit(output).split(QLatin1Char('\n')); const QStringList lines = QString::fromLocal8Bit(output).split(QLatin1Char('\n'));
const int lineCount = lines.size(); const int lineCount = lines.size();