Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Echo UTF-8 characters in Windows batch

Can I use echo to generate an UTF-8 text file? For example if I want to generate a file that contains the character ę:

echo "abcd ę" > out.txt 

(the batch file is encoded with UTF-8)

the result is an ANSI encoded file and the ę character is transformed into ê. How can I convince echo to generate an UTF-8 file?

If it's not possible, then can I change the encoding of the text file after creating it? Is there any tool in the gnuwin32 package that can help me to change the encoding?

thanks

like image 472
BearCode Avatar asked Aug 14 '12 23:08

BearCode


People also ask

What is @echo off in batch script?

batch-file Echo @Echo off @echo off prevents the prompt and contents of the batch file from being displayed, so that only the output is visible. The @ makes the output of the echo off command hidden as well.

What does %% mean in batch file?

Represents a replaceable parameter. Use a single percent sign ( % ) to carry out the for command at the command prompt. Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> )

What is echo in Windows batch file?

This batch command displays messages, or turns command echoing on or off.

What does %1 mean in a batch file?

When used in a command line, script, or batch file, %1 is used to represent a variable or matched string. For example, in a Microsoft batch file, %1 can print what is entered after the batch file name.


1 Answers

Use chcp command to change active code page to 65001 for utf-8.

chcp 65001 
like image 51
cuixiping Avatar answered Oct 24 '22 01:10

cuixiping