5454#include < QCharRef>
5555#endif
5656
57+ static QString unquote (QString s) {
58+ if (s.startsWith (" \" " ))
59+ s = s.mid (1 , s.size () - 2 );
60+ return s;
61+ }
62+
5763// NOLINTNEXTLINE(performance-unnecessary-value-param) - used as callback so we need to preserve the signature
5864int CheckThread::executeCommand (std::string exe, std::vector<std::string> args, std::string redirect, std::string &output) // cppcheck-suppress passedByValue
5965{
@@ -64,7 +70,24 @@ int CheckThread::executeCommand(std::string exe, std::vector<std::string> args,
6470 args2 << QString::fromStdString (arg);
6571
6672 QProcess process;
67- process.start (QString::fromStdString (exe), args2);
73+
74+ QString e = unquote (QString::fromStdString (exe));
75+
76+ if (e.toLower ().replace (" \\ " , " /" ).endsWith (" /python.exe" ) && !args.empty ()) {
77+ const QString path = e.left (e.size ()-11 );
78+ QProcessEnvironment env = QProcessEnvironment::systemEnvironment ();
79+ env.insert (" PYTHONPATH" , path + " /Lib/site-packages" );
80+ env.insert (" PYTHONHOME" , path);
81+ process.setProcessEnvironment (env);
82+
83+ const QString pythonScript = unquote (args2[0 ]);
84+ if (pythonScript.endsWith (" .py" )) {
85+ const QString path2 = pythonScript.left (QString (pythonScript).replace (' \\ ' , ' /' ).lastIndexOf (" /" ));
86+ process.setWorkingDirectory (path2);
87+ }
88+ }
89+
90+ process.start (e, args2);
6891 process.waitForFinished ();
6992
7093 if (redirect == " 2>&1" ) {
0 commit comments