Author pekka.klarck
Recipients pekka.klarck
Date 2020-03-10.23:36:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
While running our projects acceptance tests with Jython 2.7.2rc1 we noticed that the value of `sys.stdout.encoding` is different to what it was with earlier versions if using Windows, the current code page is different to the default code page, and stdout is redirected.

For example, on my Windows machine the default code page is 850 and by default the output of both of these commands is cp850:

  jython -c "import sys; print sys.stdout.encoding"
  jython -c "import sys; print sys.stdout.encoding"  > out.txt

If I change the code page to 437 with `chcp 437`, then the first command above correctly prints cp437  but output of the latter is cp850. With earlier Jython versions the result was cp437 in both cases.

It seems that when output is redirected, `sys.stdout.encoding` always returns the system wide code page when it should return the code page the console is using. We actually had a similar bug in our code base and there the problem was that we used Windows API function GetOEMCP when we should have used GetConsoleOutputCP.
Date User Action Args
2020-03-10 23:36:24pekka.klarcksetrecipients: + pekka.klarck
2020-03-10 23:36:24pekka.klarcksetmessageid: <>
2020-03-10 23:36:24pekka.klarcklinkissue2868 messages
2020-03-10 23:36:24pekka.klarckcreate