File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -124,12 +124,17 @@ void CPythonRunner::runFile(QString fileName)
124124
125125 PyObject* obj = Py_BuildValue (" s" , szfile);
126126 FILE * file = _Py_fopen_obj (obj, " r+" );
127- if (file == nullptr ) emit runFileFinished (false );
128-
129- PyRun_SimpleFile (file, szfile);
130-
127+ if (file == nullptr )
128+ {
129+ emit runFileFinished (false );
130+ return ;
131+ }
132+
133+ int result = PyRun_SimpleFile (file, szfile);
134+ emit runFileFinished (result == 0 );
135+ #else
136+ emit runFileFinished (false );
131137#endif
132- emit runFileFinished (true );
133138}
134139
135140#ifdef HAS_PYTHON
@@ -260,14 +265,17 @@ void CPythonRunner::runScript(QString script)
260265 }
261266
262267 std::string s = script.toStdString ();
263- PyRun_SimpleString (s.c_str ());
268+ int result = PyRun_SimpleString (s.c_str ());
264269
270+ emit runScriptFinished (result == 0 );
271+ #else
272+ emit runScriptFinished (false );
265273#endif
266- emit runScriptFinished (true );
267274}
268275
269276void CPythonRunner::setPythonCWD (const std::string& cwd)
270277{
271- std::string changeCWD = " import os\n os.chdir('" + cwd + " ')\n " ;
272- py::exec (changeCWD.c_str ());
278+ #ifdef HAS_PYTHON
279+ py::module_::import (" os" ).attr (" chdir" )(cwd);
280+ #endif
273281}
You can’t perform that action at this time.
0 commit comments