Title: os.system() encoding bug on Windows
Type: behavior Stage:
Components: Interpreter Core, Windows Versions: Python 3.0
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: amaury.forgeotdarc Nosy List: amaury.forgeotdarc, christian.heimes, r_mosaic
Priority: normal Keywords:

Created on 2007-09-24 04:51 by r_mosaic, last changed 2008-01-06 22:29 by admin. This issue is now closed.

Messages (6)
msg56101 - (view) Author: Fan Decheng (r_mosaic) Date: 2007-09-24 04:51
Python 3.0 uses utf-8 encoding, but os.system() when running on Windows 
the system default encoding, which may be "cp936" or "mbcs". They are
msg56102 - (view) Author: Fan Decheng (r_mosaic) Date: 2007-09-24 06:21
Steps to reproduce:

1. Use a Windows, with system default encoding to cp936 (Chinese PRC, or
Simplified Chinese) in Regional Options.
2. Open Python 3.0 (command line).
3. Type:
import os
import sys
os.system(("echo " + sys.stdin.readline().rstrip("\n")).encode("cp936"))
(in stdin type:)

The output from "echo" would be utf-8 mistakenly used as cp936:

Expected result:
The "echo" command outputs "我".

I guess os.system can recoding the string before sending the string out.
This may be done in the C part of Python. BTW, The os.popen() function 
msg56108 - (view) Author: Fan Decheng (r_mosaic) Date: 2007-09-24 09:07
A note about reproducing: since Windows 2000 all language packs can be 
installed easily using the Regional Options in the Control Panel. Even 
on an English version of Windows, character set mappings and fonts of 
other languages can be installed.
msg57121 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-11-05 13:16
Python 3.0 has many more problems at its boundaries to the system on
Windows. Large parts of the API that deals with Windows system calls
have to be rewritten in order to use the wide char API.
msg57678 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-11-20 01:13
Amaury is planing to remove Win95 code and use the wide api everywhere.
It should fix the bug.
msg57684 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2007-11-20 02:09
Note that the final .encode("cp936") is now invalid: os.system accepts
unicode strings, not bytes:

>>> os.system(("echo " + sys.stdin.readline().rstrip("\n")))

Corrected as r59065.
Date User Action Args
2008-01-06 22:29:45adminsetkeywords: - py3k
versions: Python 3.0
2007-11-20 02:09:29amaury.forgeotdarcsetstatus: open -> closed
resolution: fixed
messages: + msg57684
2007-11-20 01:13:22christian.heimessetnosy: + amaury.forgeotdarc
messages: + msg57678
priority: high -> normal
assignee: amaury.forgeotdarc
components: + Interpreter Core, Windows, - Library (Lib)
resolution: accepted -> (no value)
2007-11-05 13:17:00christian.heimessetpriority: normal -> high
keywords: + py3k
resolution: accepted
messages: + msg57121
nosy: + christian.heimes
2007-09-24 17:22:05jafosetpriority: normal
severity: major -> normal
2007-09-24 09:07:44r_mosaicsetmessages: + msg56108
2007-09-24 06:21:50r_mosaicsetmessages: + msg56102
2007-09-24 04:51:53r_mosaiccreate