diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2006-04-03 10:56:49 +0000 |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2006-04-03 10:56:49 +0000 |
commit | ea62d2535f6160d5b4306ea060f5da05cfa7e9ab (patch) | |
tree | d3ce394a4d53a281d208995811397a247bb764d6 /Python | |
parent | cf0a2a8576b4780263cfeb96d081eea06a1ebe92 (diff) | |
download | cpython-git-ea62d2535f6160d5b4306ea060f5da05cfa7e9ab.tar.gz |
Bug #1421664: Set sys.stderr.encoding
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pythonrun.c | 10 | ||||
-rw-r--r-- | Python/sysmodule.c | 5 |
2 files changed, 15 insertions, 0 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 4c8c5176e5..1aa6930435 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -281,6 +281,16 @@ Py_InitializeEx(int install_sigs) } Py_XDECREF(sys_isatty); + sys_stream = PySys_GetObject("stderr"); + sys_isatty = PyObject_CallMethod(sys_stream, "isatty", ""); + if (!sys_isatty) + PyErr_Clear(); + if(sys_isatty && PyObject_IsTrue(sys_isatty)) { + if (!PyFile_SetEncoding(sys_stream, codeset)) + Py_FatalError("Cannot set codeset of stderr"); + } + Py_XDECREF(sys_isatty); + if (!Py_FileSystemDefaultEncoding) Py_FileSystemDefaultEncoding = codeset; else diff --git a/Python/sysmodule.c b/Python/sysmodule.c index dfa6ac84d9..4a527424c4 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1069,6 +1069,11 @@ _PySys_Init(void) if (!PyFile_SetEncoding(sysout, buf)) return NULL; } + if(isatty(_fileno(stderr))) { + sprintf(buf, "cp%d", GetConsoleOutputCP()); + if (!PyFile_SetEncoding(syserr, buf)) + return NULL; + } #endif PyDict_SetItemString(sysdict, "stdin", sysin); |