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 <rep...@bugs.python.org> <http://bugs.python.org/issue27048> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com