Index: Python/pythonrun.c =================================================================== --- Python/pythonrun.c (revision 59842) +++ Python/pythonrun.c (working copy) @@ -1230,6 +1230,34 @@ else if (!PyString_Check(s) || PyString_GET_SIZE(s) != 0) err = PyFile_WriteString(": ", f); + +#ifdef MS_WINDOWS + if (err == 0 && PyString_Check(s) + && PyFile_Check(f)) + { + /* Special conversion: + when writing to a console, + convert from ANSI to OEM characters + */ + PyObject *enc = ((PyFileObject*)f)->f_encoding; + char oemcp[30]; + sprintf(oemcp, "cp%d", GetConsoleOutputCP()); + if (enc != Py_None + && !stricmp(PyString_AS_STRING(enc), oemcp)) { + PyObject *str; + str = PyString_FromStringAndSize( + NULL, PyString_GET_SIZE(s)); + if (str == NULL) + err = -1; + else + CharToOem( + PyString_AS_STRING(s), + PyString_AS_STRING(str)); + Py_DECREF(s); + s = str; + } + } +#endif if (err == 0) err = PyFile_WriteObject(s, f, Py_PRINT_RAW); Py_XDECREF(s);