Message266062
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". |
|
Date |
User |
Action |
Args |
2016-05-22 09:18:54 | eryksun | set | recipients:
+ eryksun, paul.moore, vstinner, tim.golden, ezio.melotti, eric.araujo, r.david.murray, martin.panter, zach.ware, steve.dower, dstufft, abarry |
2016-05-22 09:18:54 | eryksun | set | messageid: <1463908734.71.0.287308006039.issue27048@psf.upfronthosting.co.za> |
2016-05-22 09:18:54 | eryksun | link | issue27048 messages |
2016-05-22 09:18:54 | eryksun | create | |
|