| 406 | } |
| 407 | |
| 408 | static std::string detectPython(const CppCheck::ExecuteCmdFn &executeCommand) |
| 409 | { |
| 410 | #ifdef _WIN32 |
| 411 | const char *py_exes[] = { "python3.exe", "python.exe" }; |
| 412 | #else |
| 413 | const char *py_exes[] = { "python3", "python" }; |
| 414 | #endif |
| 415 | for (const char* py_exe : py_exes) { |
| 416 | std::string out; |
| 417 | #ifdef _MSC_VER |
| 418 | // FIXME: hack to avoid debug assertion with _popen() in executeCommand() for non-existing commands |
| 419 | const std::string cmd = std::string(py_exe) + " --version >NUL 2>&1"; |
| 420 | if (system(cmd.c_str()) != 0) { |
| 421 | // TODO: get more detailed error? |
| 422 | continue; |
| 423 | } |
| 424 | #endif |
| 425 | if (executeCommand(py_exe, split("--version"), "2>&1", out) == EXIT_SUCCESS && startsWith(out, "Python ") && std::isdigit(out[7])) { |
| 426 | return py_exe; |
| 427 | } |
| 428 | } |
| 429 | return ""; |
| 430 | } |
| 431 | |
| 432 | /** |
| 433 | * @throws InternalError thrown when execution fails |
no test coverage detected