我无法为文件设置编码,总是出错。我已经尝试了所有方法:
C:\ruby\sbox>ruby -W3 -Eex=utf-8 gserver.rb text.txt
ruby: unknown encoding name - ex=utf-8 (RuntimeError)
C:\ruby\sbox>ruby -W3 -Eex=utf8 gserver.rb text.txt
ruby: unknown encoding name - ex=utf8 (RuntimeError)
C:\ruby\sbox>ruby -W3 -Eex:utf8 gserver.rb text.txt
ruby: unknown encoding name - ex (RuntimeError)
C:\ruby\sbox>ruby -W3 -Eex=>utf8 gserver.rb text.txt
ruby: unknown encoding name - ex= (RuntimeError)
C:\ruby\sbox>ruby -W3 -Eex=>utf-8 gserver.rb text.txt
ruby: unknown encoding name - ex= (RuntimeError)
C:\ruby\sbox>ruby -W3 -Eexutf-8 gserver.rb text.txt
ruby: unknown encoding name - exutf-8 (RuntimeError)
C:\ruby\sbox>ruby -W3 -Eex"utf-8" gserver.rb text.txt
ruby: unknown encoding name - exutf-8 (RuntimeError)
C:\ruby\sbox>ruby -W3 -Eex="utf-8" gserver.rb text.txt
ruby: unknown encoding name - ex=utf-8 (RuntimeError)
如何设置此选项?
此参考没有-Eex
选项。
升级版:
我已经学会了。不需要打印那个ex
。只是-Eutf-8:cp866
C:\ruby\sbox>ruby -W3 -Eutf-8:cp866 gserver.rb text.txt