diff options
author | Tobias Hunger <tobias.hunger@qt.io> | 2016-07-05 13:20:10 +0200 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@qt.io> | 2016-07-15 14:22:39 +0000 |
commit | d1be129abeb2d152be30590d6a1c11d7393796d1 (patch) | |
tree | 51bced48326f69e7c25475826759a273d1cd9973 /src/libs/utils/shellcommand.cpp | |
parent | c2075f6a73139109a2d0f54d2999868967af892a (diff) |
Utils::ShellCommand: Add runSynchronous method
Add runSynchronous method and move code from runCommand there.
Change-Id: Ic7c452d583fd88468fc6466a683159ecd8328b48
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
Diffstat (limited to 'src/libs/utils/shellcommand.cpp')
-rw-r--r-- | src/libs/utils/shellcommand.cpp | 113 |
1 files changed, 61 insertions, 52 deletions
diff --git a/src/libs/utils/shellcommand.cpp b/src/libs/utils/shellcommand.cpp index a5681b7575f..f18dad69d4e 100644 --- a/src/libs/utils/shellcommand.cpp +++ b/src/libs/utils/shellcommand.cpp @@ -326,59 +326,10 @@ Utils::SynchronousProcessResponse ShellCommand::runCommand(const Utils::FileName if (!(d->m_flags & SuppressCommandLogging)) proxy->appendCommand(dir, binary, arguments); - if (d->m_flags & FullySynchronously) { + if (d->m_flags & FullySynchronously) response = runFullySynchronous(binary, arguments, proxy.data(), timeoutS, dir, interpreter); - } else { - Utils::SynchronousProcess process; - process.setExitCodeInterpreter(interpreter); - connect(this, &ShellCommand::terminate, &process, &Utils::SynchronousProcess::terminate); - process.setWorkingDirectory(dir); - - process.setProcessEnvironment(processEnvironment()); - process.setTimeoutS(timeoutS); - if (d->m_codec) - process.setCodec(d->m_codec); - - process.setFlags(processFlags()); - - // connect stderr to the output window if desired - if (d->m_flags & MergeOutputChannels) { - process.setProcessChannelMode(QProcess::MergedChannels); - } else if (d->m_progressiveOutput - || !(d->m_flags & SuppressStdErr)) { - process.setStdErrBufferedSignalsEnabled(true); - connect(&process, &Utils::SynchronousProcess::stdErrBuffered, - this, [this, proxy](const QString &text) - { - if (!(d->m_flags & SuppressStdErr)) - proxy->appendError(text); - if (d->m_progressiveOutput) - emit stdErrText(text); - }); - } - - // connect stdout to the output window if desired - if (d->m_progressParser || d->m_progressiveOutput || (d->m_flags & ShowStdOut)) { - process.setStdOutBufferedSignalsEnabled(true); - connect(&process, &Utils::SynchronousProcess::stdOutBuffered, - this, [this, proxy](const QString &text) - { - if (d->m_progressParser) - d->m_progressParser->parseProgress(text); - if (d->m_flags & ShowStdOut) - proxy->append(text); - if (d->m_progressiveOutput) { - emit stdOutText(text); - d->m_hadOutput = true; - } - }); - } - - process.setTimeOutMessageBoxEnabled(true); - - // Run! - response = process.runBlocking(binary.toString(), arguments); - } + else + response = runSynchronous(binary, arguments, proxy.data(), timeoutS, dir, interpreter); if (!d->m_aborted) { // Success/Fail message in appropriate window? @@ -454,6 +405,64 @@ Utils::SynchronousProcessResponse ShellCommand::runFullySynchronous(const Utils: return response; } +SynchronousProcessResponse ShellCommand::runSynchronous(const FileName &binary, + const QStringList &arguments, + OutputProxy *proxy, + int timeoutS, + const QString &workingDirectory, + const ExitCodeInterpreter &interpreter) +{ + Utils::SynchronousProcess process; + process.setExitCodeInterpreter(interpreter); + connect(this, &ShellCommand::terminate, &process, &Utils::SynchronousProcess::terminate); + process.setWorkingDirectory(workingDirectory); + + process.setProcessEnvironment(processEnvironment()); + process.setTimeoutS(timeoutS); + if (d->m_codec) + process.setCodec(d->m_codec); + + process.setFlags(processFlags()); + + // connect stderr to the output window if desired + if (d->m_flags & MergeOutputChannels) { + process.setProcessChannelMode(QProcess::MergedChannels); + } else if (d->m_progressiveOutput + || !(d->m_flags & SuppressStdErr)) { + process.setStdErrBufferedSignalsEnabled(true); + connect(&process, &Utils::SynchronousProcess::stdErrBuffered, + this, [this, proxy](const QString &text) + { + if (!(d->m_flags & SuppressStdErr)) + proxy->appendError(text); + if (d->m_progressiveOutput) + emit stdErrText(text); + }); + } + + // connect stdout to the output window if desired + if (d->m_progressParser || d->m_progressiveOutput || (d->m_flags & ShowStdOut)) { + process.setStdOutBufferedSignalsEnabled(true); + connect(&process, &Utils::SynchronousProcess::stdOutBuffered, + this, [this, proxy](const QString &text) + { + if (d->m_progressParser) + d->m_progressParser->parseProgress(text); + if (d->m_flags & ShowStdOut) + proxy->append(text); + if (d->m_progressiveOutput) { + emit stdOutText(text); + d->m_hadOutput = true; + } + }); + } + + process.setTimeOutMessageBoxEnabled(true); + + // Run! + return process.runBlocking(binary.toString(), arguments); +} + const QVariant &ShellCommand::cookie() const { return d->m_cookie; |