Thanks If anybody is interested, here is working code: res=PyRun_String(code,file_input,pdict_,pdict_); if (res==NULL) { if ((res=PyErr_Occurred())!=NULL) { if (PyErr_ExceptionMatches(PyExc_SystemExit)) { printf("EXIT\n"); } else { PyErr_Print(); } PyErr_Clear(); } }