Addons: If normal python fails, try 'python'
This commit is contained in:
parent
23999fece5
commit
a0f2fda53a
|
@ -169,31 +169,43 @@ static std::string executeAddon(const AddonInfo &addonInfo,
|
|||
const std::string &dumpFile)
|
||||
{
|
||||
|
||||
std::string pythonExe = cmdFileName((addonInfo.python != "") ? addonInfo.python : defaultPythonExe);
|
||||
std::string pythonExe;
|
||||
|
||||
// Can python be executed?
|
||||
const int lastTest = 3;
|
||||
for (int test = 1; test <= lastTest; ++test) {
|
||||
if (test == 1 || test == lastTest)
|
||||
pythonExe = cmdFileName((addonInfo.python != "") ? addonInfo.python : defaultPythonExe);
|
||||
else
|
||||
pythonExe = "python";
|
||||
|
||||
const std::string cmd = pythonExe + " --version 2>&1";
|
||||
|
||||
#ifdef _WIN32
|
||||
if (pythonExe.find(" ") != std::string::npos) {
|
||||
// popen strips the first quote. Needs 2 sets to fully quote.
|
||||
pythonExe = "\"" + pythonExe + "\"";
|
||||
}
|
||||
|
||||
// Can python be executed?
|
||||
{
|
||||
const std::string cmd = pythonExe + " --version 2>&1";
|
||||
|
||||
#ifdef _WIN32
|
||||
std::unique_ptr<FILE, decltype(&_pclose)> pipe(_popen(cmd.c_str(), "r"), _pclose);
|
||||
#else
|
||||
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd.c_str(), "r"), pclose);
|
||||
#endif
|
||||
if (!pipe)
|
||||
if (!pipe) {
|
||||
if (test < lastTest)
|
||||
continue;
|
||||
throw InternalError(nullptr, "popen failed (command: '" + cmd + "')");
|
||||
}
|
||||
char buffer[1024];
|
||||
std::string result;
|
||||
while (fgets(buffer, sizeof(buffer), pipe.get()) != nullptr)
|
||||
result += buffer;
|
||||
if (result.compare(0, 7, "Python ", 0, 7) != 0 || result.size() > 50)
|
||||
if (result.compare(0, 7, "Python ", 0, 7) != 0 || result.size() > 50) {
|
||||
if (test < lastTest)
|
||||
continue;
|
||||
throw InternalError(nullptr, "Failed to execute '" + cmd + "' (" + result + ")");
|
||||
}
|
||||
}
|
||||
|
||||
const std::string cmd = pythonExe + " " + cmdFileName(addonInfo.scriptFile) + " --cli" + addonInfo.args + " " + cmdFileName(dumpFile) + " 2>&1";
|
||||
|
||||
|
|
Loading…
Reference in New Issue