简体   繁体   English

Win7 Powershell回显>文本文件= Ruby2.2:无效的多字节字符(UTF-8)?

[英]Win7 Powershell echo > text file = Ruby2.2: invalid multibyte char (UTF-8)?

Can I use echo from the powershell command line to create text files which Ruby can parse? 我可以使用powershell命令行中的echo创建Ruby可以解析的文本文件吗?

>>> echo "# foobar" > echo_test.rb
>>> ruby echo_test.rb
echo_test.rb:1: invalid multibyte char (UTF-8)

Notepad++ reports the encoding as UCS-2 Little Endian. Notepad ++报告的编码为UCS-2 Little Endian。 I also tried echo'ing with the the header options mentioned in this thread: invalid multibyte char (UTF-8) Error, Ruby 我还尝试使用此线程中提到的标头选项进行回显: 无效的多字节字符(UTF-8)错误,Ruby

eg 例如

>>> echo "# encoding: utf-8" > echo_test.rb

and got the same error message. 并得到相同的错误消息。

You can change the encoding if you pipe it into Out-File 如果将其通过管道Out-FileOut-File则可以更改编码

Example: 例:

'# foobar' | Out-File -FilePath echo_test.rb -Encoding ascii
ruby echo_test.rb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM