简体   繁体   中英

Python (2.7) and reading Unicode argvs from the Windows command line

I have been following this answer on how enable Python (2.7) to correctly receive file names from the Windows command line that have names such as 'canção.pdf' , '조선.pdf' or 'मान.pdf' .

My bat file (which is in shell:sendto ) is as follows (as advised here ):

@echo off
@chcp 65001 > nul
@set PYTHONIOENCODING=utf-8
python "D:\Dropbox\Python\print_file_name.py" %1
pause

My python script at moment just tries to prints these file names:

sys.argv = win32_unicode_argv()
file_name = sys.argv[1].encode(sys.stdout.encoding)
print file_name

win32_unicode_argv() is a method described here .

Even thou I am able to print 'canção.pdf' correctly, I'm still not able to print either '조선.pdf' or 'मान.pdf' . Any advice on how to tackle this issue?

The file name is being received correctly. You can verify this by encoding sys.argv[1] as UTF-8 and writing it to a file (opened in binary mode) and then opening the file in a text editor that supports UTF-8.

The Windows command prompt is unable to display the characters correctly despite the 'chcp' command changing the codepage to UTF-8 because the terminal font does not contain those characters. The command prompt is unable to substitute characters from other fonts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM