diff options
Diffstat (limited to '3rdparty/python-console/modified/pyinterpreter.cc')
-rw-r--r-- | 3rdparty/python-console/modified/pyinterpreter.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/3rdparty/python-console/modified/pyinterpreter.cc b/3rdparty/python-console/modified/pyinterpreter.cc index f53207ad..89c9b88c 100644 --- a/3rdparty/python-console/modified/pyinterpreter.cc +++ b/3rdparty/python-console/modified/pyinterpreter.cc @@ -153,3 +153,25 @@ void pyinterpreter_release() { PyEval_ReleaseThread(m_threadState); } + +std::string pyinterpreter_execute_file(const char *python_file, int *errorCode) +{ + PyEval_AcquireThread(m_threadState); + *errorCode = 0; + std::string res; + FILE *fp = fopen(python_file, "r"); + if (fp == NULL) { + *errorCode = 1; + res = "Fatal error: file not found " + std::string(python_file) + "\n"; + return res; + } + + if (PyRun_SimpleFile(fp, python_file)==-1) { + *errorCode = 1; + PyErr_Print(); + } + res = redirector_take_output(m_threadState); + + PyEval_ReleaseThread(m_threadState); + return res; +} |