Answer the question
In order to leave comments, you need to log in
How to correctly set the code page in os.system (cmd)?
Hello.
I want to execute some commands from Python in cmd
import os
cmd = 'chcp'
os.system(cmd)
������ ������� ��࠭��: 866
Текущая кодовая страница: 866
Answer the question
In order to leave comments, you need to log in
Not sure if it can be done at all.
As far as I know, python operates on UNICODE characters and sets the console accordingly.
cmd gets along very badly with unicode.
For UTF-8 in cmd, the code page is 65001. Try to specify it in the chcp 65001 call and then specify other necessary commands through the ampersand:
cmd = 'chcp 65001 & echo Russian text& dir /b/s'
in python 3.6 and 2.7 your example gives the same error:
sh: 1: chcp: not found
32512
if you give a simple cmd = 'mkdir aaaaa' type, then everything passes ....
this is how it is written in the libref documentation ( 16.1) "Execute the command (a string) in a subshell."
There must be something wrong with Windows!!!! Check at least for ord('s') -- should be 1099 !!??
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question