Replace Python std output only for GUI application and not for CLI

This commit is contained in:
wmayer 2012-10-01 16:38:43 +02:00
parent 58da2ebbcc
commit 95de7d19cf
3 changed files with 10 additions and 3 deletions

View File

@ -343,15 +343,20 @@ const char* InterpreterSingleton::init(int argc,char *argv[])
Py_Initialize();
PySys_SetArgv(argc, argv);
PythonStdOutput::init_type();
PythonStdOutput* out = new PythonStdOutput();
PySys_SetObject("stdout", out);
PySys_SetObject("stderr", out);
this->_global = PyEval_SaveThread();
}
return Py_GetPath();
}
void InterpreterSingleton::replaceStdOutput()
{
PyGILStateLocker locker;
PythonStdOutput* out = new PythonStdOutput();
PySys_SetObject("stdout", out);
PySys_SetObject("stderr", out);
}
int InterpreterSingleton::cleanup(void (*func)(void))
{
return Py_AtExit( func );

View File

@ -193,6 +193,7 @@ public:
/// init the interpreter and returns the module search path
const char* init(int argc,char *argv[]);
int runCommandLine(const char *prompt);
void replaceStdOutput();
static InterpreterSingleton &Instance(void);
static void Destruct(void);
//@}

View File

@ -1403,6 +1403,7 @@ static void init_resources()
void Application::initApplication(void)
{
try {
Base::Interpreter().replaceStdOutput();
initTypes();
new Base::ScriptProducer( "FreeCADGuiInit", FreeCADGuiInit );
init_resources();