sublime-text-shell-command icon indicating copy to clipboard operation
sublime-text-shell-command copied to clipboard

encoding error

Open cjunekim opened this issue 9 years ago • 1 comments

Hello.

Running ShellCommand on Windows with a different locale to English has encoding issues if the output of the shell command includes non-ascii characters.

Exception in thread Thread-5: Traceback (most recent call last): File "./threading.py", line 901, in _bootstrap_inner File "./threading.py", line 858, in run File "OsShell in C:\Users\user\AppData\Roaming\Sublime Text 3\Installed Packages\ShellCommand.sublime-package", line 118, in _process UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb1 in position 11: invalid start byte

The problem originates from the line 118 in OsShell.py

                    output = proc.stdout.readline().decode().replace('\r\n', '\n')

The method decode() is used without encoding parameter set and the default, which is utf8, is used. If the system is not utf8 base, it causes problems. Instead, it should have been something like:

                    output = proc.stdout.readline().decode(locale.getpreferredencoding()).replace('\r\n', '\n')

Or, at least, the encoding should be changeable by configuration.

cjunekim avatar Mar 07 '16 18:03 cjunekim

The solution looks fair enough...I'll look at adding it.

Will need to get a Windows VM to verify it, though.

markbirbeck avatar Sep 16 '18 11:09 markbirbeck