Is it possible to save a text file in UTF-8 encoding using Windows' command line cmd.exe?
Current I'm creating the text file using command redirection operators:
C:\Windows\system32\ipconfig /all >> output.log
I start with > to get a new file and then I use >> to append more information.
Click Tools, then select Web options. Go to the Encoding tab. In the dropdown for Save this document as: choose Unicode (UTF-8). Click Ok.
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.
chcp 65001
C:\Windows\system32\ipconfig /all >> output.log
Change it back to default when done.
chcp 1252
                        As the existing answer says, in a batch file, you can use the chcp command
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 /c chcp 65001 > nul & cmd.exe /c some_command > file
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With