| 17 | #include <string> |
| 18 | |
| 19 | QString ExecProcess(QString const & program, std::initializer_list<QString> args, QProcessEnvironment const * env) |
| 20 | { |
| 21 | QStringList qargs(args); |
| 22 | QProcess p; |
| 23 | if (nullptr != env) |
| 24 | p.setProcessEnvironment(*env); |
| 25 | |
| 26 | p.start(program, qargs, QIODevice::ReadOnly); |
| 27 | p.waitForFinished(-1); |
| 28 | |
| 29 | int const exitCode = p.exitCode(); |
| 30 | QString output = p.readAllStandardOutput(); |
| 31 | QString const error = p.readAllStandardError(); |
| 32 | if (exitCode != 0) |
| 33 | { |
| 34 | QString msg = "Error: " + program + " " + qargs.join(" ") + "\nReturned " + QString::number(exitCode); |
| 35 | if (!output.isEmpty()) |
| 36 | msg += "\n" + output; |
| 37 | if (!error.isEmpty()) |
| 38 | msg += "\nSTDERR:\n" + error; |
| 39 | throw std::runtime_error(msg.toStdString()); |
| 40 | } |
| 41 | if (!error.isEmpty()) |
| 42 | { |
| 43 | QString msg = "STDERR with a zero exit code:\n" + program + " " + qargs.join(" "); |
| 44 | msg += "\nSTDERR:\n" + error; |
| 45 | LOG(LINFO, (msg.toStdString())); |
| 46 | } |
| 47 | return output; |
| 48 | } |
| 49 | |
| 50 | bool CopyFile(QString const & oldFile, QString const & newFile) |
| 51 | { |