原文链接
http://blog.csdn.net/bbdxf/article/details/25594703
[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", }
我们可以通过修改ruby.sublime-build来修改输出文字信息的编码.
2.将ruby.sublime-build复制到sublime text的Data\Packages\User\目录
以上这种修改有局限,比如我有时候输出的是utf-8,有时候输出的是gbk,这时候就不行了.
1.在sublime text的安装目录下的Packages\目录下找到Default.sublime-package,将这个复制出来,将后缀改名为zip.
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两种编码都试试,这样可以解决编码错误的问题.