windows 使用 cmd.exe 以 UTF-8 编码保存文本文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16598785/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Save text file in UTF-8 encoding using cmd.exe
提问by user2333346
Is it possible to save a text file in UTF-8 encoding using Windows' command line cmd.exe?
是否可以使用 Windows 的命令行 cmd.exe 以 UTF-8 编码保存文本文件?
回答by rchn
The default encoding for command prompt is Windows-1252. Change the code page (chcp command) to 65001 (UTF-8) first and then run your command.
命令提示符的默认编码是 Windows-1252。首先将代码页(chcp 命令)更改为 65001 (UTF-8),然后运行您的命令。
chcp 65001
C:\Windows\system32\ipconfig /all >> output.log
Change it back to default when done.
完成后将其更改回默认值。
chcp 1252
回答by Martin Prikryl
As the existing answer says, in a batch file, you can use the chcp
command
正如现有答案所说,在批处理文件中,您可以使用chcp
命令
chcp 65001 > nul
some_command > file
But if you are using the cmd.exe
from its command line, e.g. to execute a user-defined command, you can use this syntax:
但是,如果您cmd.exe
从其命令行使用 ,例如执行用户定义的命令,则可以使用以下语法:
cmd.exe /c chcp 65001 > nul & cmd.exe /c some_command > file