MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / executeCommand

Method executeCommand

gui/checkthread.cpp:61–105  ·  view source on GitHub ↗

NOLINTNEXTLINE(performance-unnecessary-value-param) - used as callback so we need to preserve the signature

Source from the content-addressed store, hash-verified

59
60// NOLINTNEXTLINE(performance-unnecessary-value-param) - used as callback so we need to preserve the signature
61int 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
108CheckThread::CheckThread(ThreadResult &result, int threadIndex)

Callers

nothing calls this directly

Calls 9

terminatedFunction · 0.85
endsWithMethod · 0.80
unquoteFunction · 0.70
QStringClass · 0.70
startsWithFunction · 0.50
clearMethod · 0.45
replaceMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected