[issue27048] distutils._msvccompiler._get_vc_env() fails with UnicodeDecodeError if an env var is not encodable

Eryk Sun report at bugs.python.org
Sun May 22 05:18:54 EDT 2016


Eryk Sun added the comment:

When writing to a file or pipe, cmd's internal commands default to either the current codepage of the attached console or, for a detached process, the system locale codepage. It uses a best-fit encoding that tries to map characters to similar characters in the codepage. For example:

    >>> win_unicode_console.enable()
    >>> os.environ['TEST©'] = '®'
    >>> out = subprocess.check_output('cmd /c set test')
    >>> out.decode(sys.__stdout__.encoding).strip()
    'TESTc=r'

You can force it to use Unicode (UTF-16LE) with the /u option:

    >>> out = subprocess.check_output('cmd /u /c set test')
    >>> out.decode('utf-16le').strip()
    'TEST©=®'

subprocess could use "/u /c" instead of "/c". This would only affect the output of internal shell commands such as "dir" and "set".

----------
nosy: +eryksun

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27048>
_______________________________________


More information about the Python-bugs-list mailing list