Drekin / win-unicode-console

A Python package to enable Unicode support when running Python from Windows console.
MIT License
103 stars 12 forks source link

Unicode filename gets crippled when drag-and-dropped #31

Closed Drekin closed 7 years ago

Drekin commented 8 years ago

When a Python script is run by drag-and-dropping another file, its path gets crippled in sys.argv if it contains Unicode characters, and our unicode_argv module doesn't resolve this. Note that this is an issue even in Python 3. Since even calling GetCommandLineW returns a crippled path, this may be issue with Windows itself. I have started an issue in Python bug tracker: http://bugs.python.org/issue27469.

Drekin commented 8 years ago

This is not a bug of win_unicode_console or even of Python. It is a bug in Windows drop handler {60254CA5-953B-11CF-8C96-00AA00B8708C} – somewhere it degrades to ANSI. A workaround is to manually change the drop handler in registries: change value in HKEY_CLASSES_ROOT\Python.File\shellex\DropHandler from {60254CA5-953B-11CF-8C96-00AA00B8708C} to {86C86720-42A0-1069-A2E8-08002B30309D}, which is the handler exe and bat files use. The observations come from Eryk Sun (see http://bugs.python.org/issue27469).

The handler uses short paths, which is no problem for functionality, they are just uglier to read. Maybe I'll add an explicit conversion to long paths into unicode_argv.

MXS2514 commented 8 years ago

Thank you for response. Using short paths handler did work functionality, however, it changed input filename. When doing save operations, the output filename become shorten one, which isn't my expectation(unicodenamein,unicodenameout). Since it's windows' glitch, the current solution test.bat:

set curdir=%~dp0
cd /d %curdir%

test.py %1

is enough for me.

Drekin commented 7 years ago

Hello, the issue was fixed for new versions of Python 3: http://bugs.python.org/issue27469 .