Issue 1193: os.system() encoding bug on Windows (original) (raw)

Created on 2007-09-24 04:51 by r_mosaic, last changed 2022-04-11 14:56 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 uses the system default encoding, which may be "cp936" or "mbcs". They are incompatible.
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:) 我 Result: The output from "echo" would be utf-8 mistakenly used as cp936: 鎴? Expected result: The "echo" command outputs "我". Comments: 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 is correct.
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.
History
Date User Action Args
2022-04-11 14:56:27 admin set github: 45534
2008-01-06 22:29:45 admin set keywords: - py3kversions: Python 3.0
2007-11-20 02:09:29 amaury.forgeotdarc set status: open -> closedresolution: fixedmessages: +
2007-11-20 01:13:22 christian.heimes set nosy: + amaury.forgeotdarcmessages: + priority: high -> normalassignee: amaury.forgeotdarccomponents: + Interpreter Core, Windows, - Library (Lib)resolution: accepted -> (no value)
2007-11-05 13:17:00 christian.heimes set priority: normal -> highkeywords: + py3kresolution: acceptedmessages: + nosy: + christian.heimes
2007-09-24 17:22:05 jafo set priority: normalseverity: major -> normal
2007-09-24 09:07:44 r_mosaic set messages: +
2007-09-24 06:21:50 r_mosaic set messages: +
2007-09-24 04:51:53 r_mosaic create