The Windows version of the mongo shell changes the console code page from its initial setting to CP_UTF8 (65001) in order to accomodate UTF-8 output that is not routed through the writeUtf8ToWindowsConsole() function in src/mongo/util/text.cpp.
This code page switching causes a problem if the shell is abnormally exited (segfault or some other abort) because the initial code page is not restored on exit in that case. This leaves the console set to the UTF-8 code page, and other programs (e.g. Python) may complain.
We should remove the code page switching code and let non-ASCII text displayed with, for example, "cout" just display badly (as corrupted text). This may encourage us to remove any remaining code paths that don't go through writeUtf8ToWindowsConsole().
Here's the code: src/mongo/shell/dbshell.cpp lines 1136 to 1154 in the current master branch:
int wmain(int argc, wchar_t* argvW[], wchar_t* envpW[]) { static mongo::StaticObserver staticObserver; UINT initialConsoleInputCodePage = GetConsoleCP(); UINT initialConsoleOutputCodePage = GetConsoleOutputCP(); SetConsoleCP( CP_UTF8 ); SetConsoleOutputCP( CP_UTF8 ); int returnCode; try { WindowsCommandLine wcl(argc, argvW, envpW); returnCode = _main(argc, wcl.argv(), wcl.envp()); } catch ( mongo::DBException& e ) { cerr << "exception: " << e.what() << endl; returnCode = 1; } SetConsoleCP( initialConsoleInputCodePage ); SetConsoleOutputCP( initialConsoleOutputCodePage ); ::_exit(returnCode); }
Lines 3 to 6 and 16 through 17 in this excerpt should be removed.