Net::SSH UTF-8 问题

使用Ruby 2.0 on Rails 4.0。如果你通过Net::SSH执行命令,输出的时候包含UTF-8文字,就会出现编码错误:

“\xE5” from ASCII-8BIT to UTF-8

或者

incompatible character encodings: ASCII-8BIT and UTF-8

当你强制设置各种 UTF-8 或者 ASCII-8BIT 编码时:

Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8

或者

config.encoding = “utf-8”

又或者

# encoding: utf-8

你都会发觉徒劳无功,因为问题不知道是出在哪里。

濒临绝望的时候,何不用另外的思维转换一下?

你大可以在输出的时候用Base64编码,然后浏览器用Base64解码。一切顺利!

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com 徽标

You are commenting using your WordPress.com account. Log Out /  更改 )

Google+ photo

You are commenting using your Google+ account. Log Out /  更改 )

Twitter picture

You are commenting using your Twitter account. Log Out /  更改 )

Facebook photo

You are commenting using your Facebook account. Log Out /  更改 )

w

Connecting to %s