fixes #0004000: Ability to suppress console output when running under python

This commit is contained in:
wmayer
2019-06-13 15:46:49 +02:00
parent 98a53884dc
commit fdcd36f251
4 changed files with 17 additions and 2 deletions

View File

@@ -1536,8 +1536,10 @@ void Application::initConfig(int argc, char ** argv)
// Init console ===========================================================
Base::PyGILStateLocker lock;
_pConsoleObserverStd = new ConsoleObserverStd();
Console().AttachObserver(_pConsoleObserverStd);
if (mConfig["LoggingConsole"] == "1") {
_pConsoleObserverStd = new ConsoleObserverStd();
Console().AttachObserver(_pConsoleObserverStd);
}
if (mConfig["Verbose"] == "Strict")
Console().UnsetConsoleMode(ConsoleSingleton::Verbose);

View File

@@ -82,6 +82,7 @@ int main( int argc, char ** argv )
// Init phase ===========================================================
// sets the default run mode for FC, starts with command prompt if not overridden in InitConfig...
App::Application::Config()["RunMode"] = "Exit";
App::Application::Config()["LoggingConsole"] = "1";
// Inits the Application
App::Application::init(argc,argv);

View File

@@ -187,6 +187,7 @@ int main( int argc, char ** argv )
// sets the default run mode for FC, starts with gui if not overridden in InitConfig...
App::Application::Config()["RunMode"] = "Gui";
App::Application::Config()["Console"] = "0";
App::Application::Config()["LoggingConsole"] = "1";
// Inits the Application
#if defined (FC_OS_WIN32)

View File

@@ -42,10 +42,12 @@
#include <stdio.h>
#include <sstream>
#include <iostream>
// FreeCAD Base header
#include <Base/Exception.h>
#include <Base/Sequencer.h>
#include <App/Application.h>
@@ -228,6 +230,15 @@ PyMOD_INIT_FUNC(FreeCAD)
free(argv[0]);
free(argv);
Base::EmptySequencer* seq = new Base::EmptySequencer();
(void)seq;
static Base::RedirectStdOutput stdcout;
static Base::RedirectStdLog stdclog;
static Base::RedirectStdError stdcerr;
std::cout.rdbuf(&stdcout);
std::clog.rdbuf(&stdclog);
std::cerr.rdbuf(&stdcerr);
#if PY_MAJOR_VERSION >= 3
//PyObject* module = _PyImport_FindBuiltin("FreeCAD");
PyObject* modules = PyImport_GetModuleDict();