Wehn I issue from a DOS batch file the following command:
echo foobar >myfile.txt
then myfile.txt will always be created as UCS-2 Little Endian based file
How can I tell the DOS batch execution to create an UTF-8 file instead?
Peter
How to create an UTF-8 file (instead of UCS-2 Little Endian)?
Moderator: DosItHelp
Re: How to create an UTF-8 file (instead of UCS-2 Little Endian)?
Serioulsly? I can't believe that. It's definitely not the default behavior.
The Windows has kind of UTF-8 support. It's rather bad though.
Code: Select all
@echo off
>nul chcp 1252
set "x=åéøü"
>nul chcp 65001
>"utf8test.txt" echo %x%
Steffen
Re: How to create an UTF-8 file (instead of UCS-2 Little Endian)?
I thought we had a thread going on the forum about creating a UTF-8 file with a BOM. I can't find it.
Re: How to create an UTF-8 file (instead of UCS-2 Little Endian)?
I'm absolutely sure we have several threads with examples of how to write the BOM. Everyone has the possibility to search for UTF-8 in the forum.
Nevermind.
Still dependent on the encoding used in the editor to save the script. Other possibilities would have been to use UTF-7 or CERTUTIL. Also it's not a big deal to use JREPL.BAT or CONVERTCP.exe to convert the file afterwards to any encoding you want. Both tools to be found in this forum, too.
Steffen
Nevermind.
Code: Select all
@echo off
>nul chcp 1252
set "x=åéøü"
<nul >"utf8test.txt" set /p "="
>nul chcp 65001
>>"utf8test.txt" echo %x%
Steffen