How to make cmd and batch script display correctly arabic characters?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Hackoo
Posts: 103
Joined: 15 Apr 2014 17:59

How to make cmd and batch script display correctly arabic characters?

#1 Post by Hackoo » 10 Feb 2018 10:27

I have tried this code to show some strings in arabic, but the charachters are shown as : â?â?ل?â?

Code: Select all

@echo off
setlocal enableExtensions enableDelayedExpansion
set "cp="
for /F "tokens=2 delims=:." %%a in ('chcp') do set "cp=%%~a"
if not defined cp set "cp=850"
>nul chcp 1256 
set "quarterNote=مهدي"
>nul chcp %cp%
echo(!quarterNote!
endlocal
pause & exit
So the output expected is like this : مهدي
Is there any solution for this issue ?

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: How to make cmd and batch script display correctly arabic characters?

#2 Post by penpen » 10 Feb 2018 13:59

I think this should work (untested - i have to install some fonts on my pc to check the result):

Code: Select all

@echo off
setlocal enableExtensions enableDelayedExpansion
::ÿþ
set "cp="
for /F "tokens=2 delims=:." %%a in ('chcp') do set "cp=%%~a"
if not defined cp set "cp=850"
>nul chcp 65001
:: D9 85 D9 87 D8 AF D9 8A
set "text=مهدي"
>nul chcp %cp%

echo(!text!
endlocal
pause
exit /b
The utf-8 byte sequence for your text should be D9 85 D9 87 D8 AF D9 8A (if i am not wrong).
The codepage 1252 codepoints for the hex values D9, 85, ... 8A are all defined (see the codepage 1252 linked here), so you don't need to access additional codepages.

penpen

Hackoo
Posts: 103
Joined: 15 Apr 2014 17:59

Re: How to make cmd and batch script display correctly arabic characters?

#3 Post by Hackoo » 10 Feb 2018 14:16

Still dosen't work :(

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: How to make cmd and batch script display correctly arabic characters?

#4 Post by penpen » 10 Feb 2018 15:57

It took me a while to install a proper font to dispaly the characters.
On my system the above script works as intended.

There might be multiple reasons why the script doesn't work properly on your pc;
for example (incomplete list):
1) I initially wondered, why you set the codepage in your OP to 1256.
Now i think: Maybe the default ANSI codepage of your system is not 1252 but 1256.
You may check this with a batch linked here:
viewtopic.php?f=3&t=6108#p49091

2)Another possibility is, that you don't use notepad to create the above batch (other editors may use different codepages).

3) It also might be, that your browser (or mine) doesn't display the characters correctly, so we talk about different characters.


penpen

Hackoo
Posts: 103
Joined: 15 Apr 2014 17:59

Re: How to make cmd and batch script display correctly arabic characters?

#5 Post by Hackoo » 10 Feb 2018 16:34

Code: Select all

 INFO.BAT version 1.4
--------------------------------------------------------------------------------
Windows version        :  Microsoft Windows [version 10.0.16299.125]
Product name           :  Windows 10 Pro, 32 bit
Performance indicators :  Processor Cores: 4      Visible RAM: 2705772 kilobytes

Date/Time format       :  (dd/mm/yy)  Sat 02/10/2018  23:31:38.51
__APPDIR__             :  C:\Windows\system32\
ComSpec                :  C:\Windows\system32\cmd.exe
PathExt                :  .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
Extensions             :  system: Enabled   user: Enabled 
Delayed expansion      :  system: Disabled  user: Disabled
Locale name            :  ar-TN       Code Pages: OEM  720    ANSI 1256
DIR  format            :  02/10/2018  02:02 PM     3,698,982,912 pagefile.sys
Permissions            :  Elevated Admin=No, Admin group=Yes
I used Notepad++ as editor

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How to make cmd and batch script display correctly arabic characters?

#6 Post by aGerman » 10 Feb 2018 17:57

Notepad++ provides the possibility to set the encoding to a certain charset. Have a look at the menu item "Encoding" > "Character Set" > "Arabic" and choose "OEM 720". Omit any changes of the codepage in the script (using CHCP). I assume the only reason why it may not work is if the font you set for the console window doesn't support arabic letters.
Try the attached code. (Of course it won't work for people where the OEM code page doesn't default to 720.)

Steffen
Attachments
test_arab.zip
(220 Bytes) Downloaded 1092 times

Hackoo
Posts: 103
Joined: 15 Apr 2014 17:59

Re: How to make cmd and batch script display correctly arabic characters?

#7 Post by Hackoo » 11 Feb 2018 15:40

Thank you both of you (penpen and aGerman) for your assistance and your help :wink:

Post Reply