C
C
ChernovDmitry2014-01-29 14:14:59
Python
ChernovDmitry, 2014-01-29 14:14:59

How to pass parameters containing Cyrillic characters from windows bat file to python interpreter?

For example, a bat file is like this:
python my_program.py параметр1 параметр2
Python program prints krakozyabry:

import sys

source_file = sys.argv[1]
dest_file = sys.argv[2]

print( "исходный файл : " + source_file )
print( "результирующий файл " + dest_file )

The bat nickname itself is encoded in cp1251. The words "Source file" and "Result file" are printed normally. Upd: bugs also appear on the windows command line (before python). Looks like python has nothing to do with it

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Grebenshchikov, 2014-01-29
@archerz

You need to add a line to the batch file:
chcp 1251
python my_program.py parameter1 parameter2
or save the batch file in 866 encoding

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question