Some of the outputs from cygwin just can not be read with bad encoding?

若如初见. 提交于 2020-01-01 19:03:01

问题


I'm using cygwin on Win7-64bit, and with "zh_CN.UTF-8" as default locale setting. Occasionally, some of the outputs from cygwin just can not be read with bad encoding like follows:

[junit] ▒▒▒▒: ▒Ҳ▒▒▒▒▒▒޷▒▒▒▒▒▒▒▒▒ can't

Any idea? Thanks.


回答1:


Although sharajava have found a solution by himself, I have to say that this solution is not very preferable at least for me. The problem is if you change the Terminal Options of Text ("CharSet" of mintty actually) to "GBK", what will UTF-8 characters display on screen? They will be messy, unreadable code. I experimented on VIM, whether its chinese welcome text or UTF-8 encoded source code including chinese characters displays as unreadable code. It's not acceptable for me or, as I guess, most people.

Finally I figured out a way to bypass the flaw of Windows command prompt (i.e. cmd.exe) and enabling mintty running DOS commands without suffering from messy codes. Here is my solution and may it be helpful.

Testing environment:
OS: Win7 64-bit Chinese Simplified
Cygwin: 64-bit
Command Prompt: default code-page 936

Configuration:

  • Set locale of Cygwin to zh_CN.UTF-8 as most people desired
  • Add Locale=zh_CN and Charset=UTF-8 to .minttyrc making mintty use UTF-8 as output encoding
  • Add cmd /c chcp 65001 to .bashrc

Now you are able to run DOS commands like ipconfig, taskkill, help.exe and format.com etc directly on mintty, even in companion with linux commands such as less,grep. Every time you login in bash, it will tell you Active code page: 65001 meaning the output encoding of cmd.exe has been temporarily changed to UTF-8.

When code-page of cmd.exe is changed to 65001, cmd.exe will no longer use Chinese as hint text language (English instead) and Chinese directories are not supported either. This is a defect of cmd.exe and has nothing to do with mintty. Somehow, mintty manages to output Chinese characters which cmd.exe with cp65001 cannot. I can't explain this, anyway, it works.

To set locale of cygwin, you can add following code to your .bashrc:

export LC_ALL=zh_CN.UTF-8
export LC_CTYPE=zh_CN.UTF-8
export LANG=zh_CN.UTF-8

See also:
Unicode characters in Windows command line - how?
My application prints international characters but I only see gray boxes




回答2:


http://cygwin.com/faq-nochunks.html#faq.using.weirdchars

It's just caused by some Chinese character here.

Change the Terminal Options of Text, choose character set as "GBK". It works.



来源:https://stackoverflow.com/questions/10510618/some-of-the-outputs-from-cygwin-just-can-not-be-read-with-bad-encoding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!