是否可以使用Windows的命令行cmd.exe以UTF-8编码保存文本文件?
命令提示符的默认编码是Windows-1252。 首先将代码页(chcp命令)更改为65001(UTF-8),然后运行您的命令。
chcp 65001 C:\Windows\system32\ipconfig /all >> output.log
完成后将其更改回默认值。
chcp 1252
正如现有的答案所说,在批处理文件中,您可以使用chcp
命令
chcp 65001 > nul some_command > file
但是,如果从命令行使用cmd.exe
,例如执行用户定义的命令,则可以使用以下语法:
cmd.exe /c chcp 65001 > nul & cmd.exe /c some_command > file