From 27f83e1801e322f6aab4829812ea22a396b762a0 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Thu, 29 Oct 2015 11:42:16 -0700 Subject: [PATCH] Refactor duplicated code #4933 --- src/gui/src/CoreInterface.cpp | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/src/gui/src/CoreInterface.cpp b/src/gui/src/CoreInterface.cpp index 1a917382..4705b8cc 100644 --- a/src/gui/src/CoreInterface.cpp +++ b/src/gui/src/CoreInterface.cpp @@ -17,6 +17,8 @@ #include "CoreInterface.h" +#include "CommandProcess.h" + #include #include #include @@ -83,33 +85,7 @@ QString CoreInterface::run(const QStringList& args, const QString& input) QCoreApplication::applicationDirPath() + "/" + kCoreBinary); - QProcess process; - process.setReadChannel(QProcess::StandardOutput); - process.start(program, args); - bool success = process.waitForStarted(); + CommandProcess commandProcess(program, args, input); + return commandProcess.run(); - QString output, error; - if (success) - { - if (!input.isEmpty()) { - process.write(input.toStdString().c_str()); - } - - if (process.waitForFinished()) { - output = process.readAllStandardOutput().trimmed(); - error = process.readAllStandardError().trimmed(); - } - } - - int code = process.exitCode(); - if (!error.isEmpty() || !success || code != 0) - { - throw std::runtime_error( - QString("Code: %1\nError: %2") - .arg(process.exitCode()) - .arg(error.isEmpty() ? "Unknown" : error) - .toStdString()); - } - - return output; }