graphic ascii characters not working

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
rasil
Posts: 6
Joined: 23 Apr 2020 13:05

graphic ascii characters not working

#1 Post by rasil » 17 Jul 2020 05:22

hi everyone,

I just want to create a progress bar but these characters ▒ are not working ! please help :cry:

here is the sample code:
@echo off
echo Û
echo ±
echo °
pause

please view the attached file to see what i get

any help would be nice :wink:
Attachments
Captuddre.PNG
Captuddre.PNG (1.37 KiB) Viewed 376 times

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

Re: graphic ascii characters not working

#2 Post by penpen » 17 Jul 2020 06:06

Basing on your result, i suspect your console uses codepage 850 and you saved your batch file as UTF-8.
You could either save your batch file as ANSI, or you could set your console (temporary) to display UTF-8 characters (codepage 65001) and use the characters directly.

Option "test.ansi.bat":

Code: Select all

@echo off
echo Û
echo ±
echo °
pause
Option "test.utf-8.bat":

Code: Select all

@echo off
setlocal enableExtensions disableDelayedExpansion
:: save old codepage
for /f "tokens=*" %%a in ('chcp') do for %%b in (%%a) do set "cp=%%~nb"
>nul chcp 65001

echo █
echo ▒
echo ░

>nul chcp %cp%
pause

goto :eof

penpen

rasil
Posts: 6
Joined: 23 Apr 2020 13:05

Re: graphic ascii characters not working

#3 Post by rasil » 17 Jul 2020 06:19

thanks for replaying,

will this be a problem to other people? or i have something wrong with my cmd and can you explain a bit more about: "and you saved your batch file as UTF-8."

if any misunderstanding sorry I am a Big noob when it comes to batch

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

Re: graphic ascii characters not working

#4 Post by penpen » 17 Jul 2020 08:04

Depending on how you share the batch-script-code with other people, there could be a problem.
If you zip your file and share your zip, then there is no problem (for other win 10 users, if you force your default codepage similar to the UTF-8 example).
If someone just copies your code and saves it to a file, then he has to ensure he/she/... uses the same encoding that you are using, so you should mention that somewhere.

There is nothing wrong with your cmd.
Just notice that different windows versions might have different default encodings for both windos and dos programs.

UTF-8 is one of multiple representations for data.
If you are using "notepad.exe", then you could choose "File" -> "Save As";
in the dialog that opens, you can choose the encoding (left of the "Save"-button).


penpen

Post Reply