Sublime text 2/3 [Decode error - output not utf-8] 完美解決方法
sublime text有時執行會輸出以下錯誤資訊:
[Decode error - output not utf-8]或者[Decode error - output not gbk]
錯誤資訊意思就是指令碼輸出的資訊不是某種指定編碼.
指定的編碼一般在XX.sublime-build裡,比如ruby.sublime-build的內容為:
{
"shell_cmd": "ruby \"$file\"",
"file_regex": "(\\w:...*?):([0-9]*):?([0-9]*)",
"selector": "source.ruby",
"encoding": "utf-8",
}
其中encoding就是指定的編碼,ruby.sublime-build可以在Sublime Text 3\Packages\Ruby.sublime-package裡找到.
我們可以通過修改ruby.sublime-build來修改輸出文字資訊的編碼.
1. 將ruby.sublime-build檔案從Ruby.sublime-package裡複製出來,(注意:Ruby.sublime-package是一個zip壓縮檔案,只要將其字尾名改為zip即可開啟這個壓縮檔案)
2.將ruby.sublime-build複製到sublime text的Data\Packages\User\目錄
3. 開啟此檔案,將此檔案中的"encoding": "utf-8"修改為"encoding": "gbk"
以上這種修改有侷限,比如我有時候輸出的是utf-8,有時候輸出的是gbk,這時候就不行了.
以下方法可以解決這個侷限.
1.在sublime text的安裝目錄下的Packages\目錄下找到Default.sublime-package,將這個複製出來,將字尾改名為zip.
是的,它就是個zip檔案,解壓縮它,然後將其中的exec.py檔案放到sublime text的Data\Packages\User\目錄下.
2.開啟exec.py.找到類ExecCommand的append_data函式,在以下位置新增程式碼
def append_data(self, proc, data):
if proc != self.proc:
# a second call to exec has been made before the first one
# finished, ignore it instead of intermingling the output.
if proc:
proc.kill()
return
#add start
is_decode_ok = True;
try:
str = data.decode(self.encoding)
except:
is_decode_ok = False
if is_decode_ok==False:
try:
str = data.decode("gbk")
except:
str = "[Decode error - output not " + self.encoding + " and gbk]\n"
proc = None
# Normalize newlines, Sublime Text always uses a single \n separator
# in memory.
str = str.replace('\r\n', '\n').replace('\r', '\n')
self.output_view.run_command('append', {'characters': str, 'force': True, 'scroll_to_end': True})
其原理就是在解碼輸出文字編碼出錯時再使用gbk試試,相當於utf-8和gbk兩種編碼都試試,這樣可以解決編碼錯誤的問題.
作者:hgyxbll,原文連結:http://shashanzhao.com/archives/976.html
相關文章
- Sublime Text 2報 Decode error - output not utf-8 錯誤的解決辦法Error
- sublime上配置java環境,解決Decode error - output not utf-8問題JavaError
- Could not decode a text frame as UTF-8 的解決
- Sublime Text 3 中文亂碼問題的解決
- 解決IDEA Error:Output directory is not specifiedIdeaError
- ASBFAT:Sublime Text 3
- Sublime text3 舒爽配置
- Sublime Text 3 安裝 BracketHighlighterRacket
- Jou 的解決方案系列:Sublime Text 3 使用之自動儲存
- [sublime系列文章] sublime text 3如何設定巨集
- 解決 sublime text3 執行python檔案無法input的問題Python
- MacOS Sublime Text 3 安裝使用 Sublime-phpcs 外掛MacPHP
- sublime text3 好用的外掛
- sublime Text3 前端常用外掛前端
- Sublime Text 3 如何支援中文編碼
- sublime text 3 自制快速程式碼片段
- sublime text3外掛安裝
- Sublime Text3中 less 自動編譯成 css 的方法編譯CSS
- 【解決方案】Windows 環境 Sublime Text 4 中缺少 Package ControlWindowsPackage
- mount error(5): Input/output errorError
- sublime text3 顯示空格和Tab
- Sublime Text 3 下載安裝及配置
- 更改 Sublime text 3 側邊欄字型大小
- 使用 Sublime Text 3 編譯 C 語言編譯
- 編輯器之——Sublime Text3、Notepad++
- Sublime text3 無法安裝外掛
- Sublime Text 3 的微信小程式外掛!微信小程式
- sublime text for Mac註冊啟用 sublime text4註冊碼Mac
- Invalid byte 3 of 3-byte UTF-8 sequence 解決方案
- Sublime Text 4.0 Mac版Mac
- 程式碼編輯器Sublime_Text3的使用
- Sublime Text3 自動編譯less 的配置編譯
- Markdown | win10系統MarkEditor轉Sublime Text 3Win10
- 使用sublime text3搭建Python編輯環境Python
- Sublime Text 4 Dev中文破解版+Sublime Text 4 Dev啟用碼dev
- sublime text 註冊碼漢化下載+sublime text 破解安裝教程
- Composer 提示 zlib_decode (): data errorError
- Sublime Text 4 如何配置成完美的OI編輯器,優雅的打比賽
- sublime text3 - 打造成小程式開發神器