diff options
author | Tobias Hunger <tobias.hunger@qt.io> | 2016-04-29 16:52:58 +0200 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@qt.io> | 2016-05-11 10:04:38 +0000 |
commit | ddefe062c73e35def585f8fc6c90a4f18e47c0f4 (patch) | |
tree | 03c3aecc501c03b92e259fe0ae1c4d472033b7e5 /src/libs/utils/synchronousprocess.cpp | |
parent | 1a248b1b932e2c7c42e25993d921e78c52aa4bcf (diff) |
Fix up QProcess::waitForFinished()
waitForFinish returns false if the process is no longer running at
the time of the call. Handle that throughout the codebase.
Change-Id: Ia7194095454e82efbd4eb88f2d55926bdd09e094
Reviewed-by: hjk <hjk@theqtcompany.com>
Diffstat (limited to 'src/libs/utils/synchronousprocess.cpp')
-rw-r--r-- | src/libs/utils/synchronousprocess.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/libs/utils/synchronousprocess.cpp b/src/libs/utils/synchronousprocess.cpp index 5b5d433f452..42b32bacbde 100644 --- a/src/libs/utils/synchronousprocess.cpp +++ b/src/libs/utils/synchronousprocess.cpp @@ -137,6 +137,17 @@ QString SynchronousProcessResponse::exitMessage(const QString &binary, int timeo return QString(); } +QString SynchronousProcessResponse::allOutput() const +{ + if (!stdOut.isEmpty() && !stdErr.isEmpty()) { + if (stdOut.endsWith(QLatin1Char('\n'))) + return stdOut + stdErr; + else + return stdOut + QLatin1Char('\n') + stdErr; + } + return !stdOut.isEmpty() ? stdOut : stdErr; +} + QTCREATOR_UTILS_EXPORT QDebug operator<<(QDebug str, const SynchronousProcessResponse& r) { QDebug nsp = str.nospace(); @@ -579,9 +590,8 @@ bool SynchronousProcess::readDataFromProcess(QProcess &p, int timeoutS, bool finished = false; bool hasData = false; do { - finished = p.state() == QProcess::NotRunning - || p.waitForFinished(timeoutS > 0 ? timeoutS * 1000 : -1); - hasData = false; + finished = p.waitForFinished(timeoutS > 0 ? timeoutS * 1000 : -1) + || p.state() == QProcess::NotRunning; // First check 'stdout' if (p.bytesAvailable()) { // applies to readChannel() only hasData = true; @@ -608,13 +618,13 @@ bool SynchronousProcess::readDataFromProcess(QProcess &p, int timeoutS, bool SynchronousProcess::stopProcess(QProcess &p) { - if (p.state() != QProcess::Running) + if (p.state() == QProcess::NotRunning) return true; p.terminate(); - if (p.waitForFinished(300)) + if (p.waitForFinished(300) && p.state() == QProcess::Running) return true; p.kill(); - return p.waitForFinished(300); + return p.waitForFinished(300) || p.state() == QProcess::NotRunning; } // Path utilities |