NOLINTNEXTLINE(performance-unnecessary-value-param) - used as callback so we need to preserve the signature
| 59 | |
| 60 | // NOLINTNEXTLINE(performance-unnecessary-value-param) - used as callback so we need to preserve the signature |
| 61 | int CheckThread::executeCommand(std::string exe, std::vector<std::string> args, std::string redirect, std::string &output) // cppcheck-suppress passedByValueCallback |
| 62 | { |
| 63 | output.clear(); |
| 64 | |
| 65 | QStringList args2; |
| 66 | for (const std::string &arg: args) |
| 67 | args2 << QString::fromStdString(arg); |
| 68 | |
| 69 | QProcess process; |
| 70 | |
| 71 | QString e = unquote(QString::fromStdString(exe)); |
| 72 | |
| 73 | if (e.toLower().replace("\\", "/").endsWith("/python.exe") && !args.empty()) { |
| 74 | const QString path = e.left(e.size()-11); |
| 75 | QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); |
| 76 | env.insert("PYTHONPATH", path + "/Lib/site-packages"); |
| 77 | env.insert("PYTHONHOME", path); |
| 78 | process.setProcessEnvironment(env); |
| 79 | |
| 80 | const QString pythonScript = unquote(args2[0]); |
| 81 | if (pythonScript.endsWith(".py")) { |
| 82 | const QString path2 = pythonScript.left(QString(pythonScript).replace('\\', '/').lastIndexOf("/")); |
| 83 | process.setWorkingDirectory(path2); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | process.start(e, args2); |
| 88 | while (!Settings::terminated() && !process.waitForFinished(1000)) { |
| 89 | if (process.state() == QProcess::ProcessState::NotRunning) |
| 90 | break; |
| 91 | } |
| 92 | |
| 93 | if (redirect == "2>&1") { |
| 94 | QString s1 = process.readAllStandardOutput(); |
| 95 | QString s2 = process.readAllStandardError(); |
| 96 | output = (s1 + "\n" + s2).toStdString(); |
| 97 | } else |
| 98 | output = process.readAllStandardOutput().toStdString(); |
| 99 | |
| 100 | if (startsWith(redirect, "2> ")) { |
| 101 | std::ofstream fout(redirect.substr(3)); |
| 102 | fout << process.readAllStandardError().toStdString(); |
| 103 | } |
| 104 | return process.exitCode(); |
| 105 | } |
| 106 | |
| 107 | |
| 108 | CheckThread::CheckThread(ThreadResult &result, int threadIndex) |
nothing calls this directly
no test coverage detected