Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using non-ASCII characters in a cmd batch file

I'm working on a .bat program, and the program is written in Finnish. The problem is that CMD doesn't know these "special" letters, such as Ä, Ö, Å.

Is there a way to make those work? I'd also like it if the user could use those letters too.

Part of my code:

    @echo off
    /u
    title JustATestProgram
    goto test123

    :test123
    echo Letters : Ää Öö Åå
    pause
    exit

When I open this file, the letters look like this:

Enter image description here

like image 918
batchguy11 Avatar asked Sep 15 '13 14:09

batchguy11


People also ask

How do I get out of the ampersand in CMD?

When working at the command line or with batch files, you must take one of two actions when you use strings that contain an ampersand. Either you must escape the ampersand by using the caret (^) symbol, or you must enclose the string inside quotation marks.

What does %% mean in CMD?

%% is needed in a script to avoid ambiguities. "When working at the command line (not in a batch script) there is no possibility of any batch file parameters %1, %2 etc so the logic above is not followed and hence FOR parameters on the command line only need a single %." See details. – dosentmatter. Feb 27, 2021 at 6: ...

What does %I mean in a batch command?

%%i is simply the loop variable. This is explained in the documentation for the for command, which you can get by typing for /? at the command prompt.


2 Answers

Try putting this line at the top of the batch file:

chcp 65001

It should change the console encoding to UTF-8, and you should be able to read the file properly in the script after that.

like image 174
Hari Menon Avatar answered Oct 24 '22 04:10

Hari Menon


Theoretically you just need to use the /u (Unicode) switch:

c:\>cmd /u
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

c:\>echo Ä
Ä
like image 45
Ben Avatar answered Oct 24 '22 05:10

Ben