Powershell:设置获取内容管道的编码
时间:2020-03-05 18:57:03 来源:igfitidea点击:
我有一个另存为UCS-2 Little Endian的文件,我想更改编码,所以我运行了以下代码:
cat tmp.log -encoding UTF8 > new.log
生成的文件仍在UCS-2 Little Endian中。这是因为管道始终采用这种格式吗?有没有简单的方法可以将其作为UTF8管道传输到新文件?
解决方案
回答
我会这样:
get-content tmp.log -encoding Unicode | set-content new.log -encoding UTF8
我的理解是,-encoding选项选择应该读取或者写入文件的方式。
回答
如这里的建议:
Get-Content tmp.log | Out-File -Encoding UTF8 new.log