gpt4 book ai didi

powershell - 带有 utf-8 编码的 tee

转载 作者:行者123 更新时间:2023-12-04 00:52:16 24 4
gpt4 key购买 nike

我正在尝试 tee服务器输出到控制台和 Powershell 4 中的文件。该文件以 UTF-16 编码结束,这与我正在使用的其他一些工具不兼容。根据 help tee -full :

Tee-Object uses Unicode enocding when it writes to files.
...
To specify the encoding, use the Out-File cmdlet



所以 tee不支持更改编码,以及 tee 的帮助和 Out-File不要显示任何拆分流并使用 UTF-8 对其进行编码的示例。

Powershell 4 中是否有一种简单的方法到 tee (或以其他方式拆分流)到具有 UTF-8 编码的文件?

最佳答案

一种选择是使用 Add-ContentSet-Content而不是 Out-File .
*-Content cmdlet 默认使用 ASCII 编码,并有一个 -Passthru switch 以便您可以写入文件,然后将输入传递到控制台:

Get-Childitem -Name | Set-Content file.txt -Passthru

关于powershell - 带有 utf-8 编码的 tee,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30606929/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com