输入编码:接受UTF-8
我需要在 PowerShell 下获取本机应用程序的输出。问题是,输出是用 UTF-8(无 BOM)编码的,PowerShell 无法识别它,只是将那些时髦的 UTF 字符直接转换为 Unicode。
我发现 PowerShell 有 $OutputEncoding
变量,但它似乎不影响输入数据。
好的 ol' iconv 也没有帮助,因为这个不必要的 UTF8-as-if-ASCII => Unicode 转换发生在下一个管道成员获取数据之前。
I need to get output of native application under PowerShell. The problem is, output is encoded with UTF-8 (no BOM), which PowerShell does not recognize and just converts those funky UTF chars directly into Unicode.
I've found PowerShell has $OutputEncoding
variable, but it does not seem to affect input data.
Good ol' iconv is of no help either, since this unnecessary UTF8-as-if-ASCII => Unicode conversion takes place before the next pipeline member acquires data.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我现在看到下面的程序存在问题(stdout.cpp - cl stdout.cpp):
并通过
| 运行该程序Out-File -enc UTF8 foo.txt
给出了乱码:请注意,fhex 是一个 PSCX 实用程序。
更新:弄清楚如何让它发挥作用:
I see the issue now with the program below (stdout.cpp - cl stdout.cpp):
And running that through
| Out-File -enc UTF8 foo.txt
gives the gibberish:Note that fhex is a PSCX utility.
UPDATE: Figured out how to get this to work:
可能你需要执行“chcp 65001”(修改powershell.exe的字体后)。
此命令可通过 PSISE 使用。
Probabry you need to execute "chcp 65001" (after modifying powershell.exe's font).
This command is available with PSISE.
如果您的目标是在 powershell 中处理来自本机命令的数据,您可以尝试
If your goal is to process data from your native command in powershell, you may try