Page 1 of 1

ASCII in batch

Posted: 02 Apr 2012 18:16
by MrKnowItAllxx
I know there is a really simple solution to this problem, its just I don't know what chart to look up or what I really need

I just want to get extended ascii characters like ▓ ▒ ░ into batch, but I am unable to save files with such characters

I know of three characters ° ± ² that when put into batch, are interpreted as the three above characters, but I don't know what chart online would tell me other characters like that which are interpreted as extended ascii characters in batch

Any help is appreciated

Re: ASCII in batch

Posted: 02 Apr 2012 18:38
by foxidrive
The font and maybe the code page you display text in has a bearing on this.

Check that the font you are using has those characters.

Re: ASCII in batch

Posted: 02 Apr 2012 18:56
by MrKnowItAllxx
Found what I need here: http://www.jimprice.com/jim-asc.shtml

"Microsoft Windows ® has a different notion about what the high-order (upper 128) characters are"

Re: ASCII in batch

Posted: 02 Apr 2012 19:40
by Liviu
You don't tell the purpose of getting those characters in a batch file to begin with. If that's for making or checking pathnames on disk, then all you need is to get the codepage matching between the editor used to save the batch file, and the cmd prompt used to execute it. If it's for echo and console display purposes, you additionally need a font which carries those characters.

MrKnowItAllxx wrote:I just want to get extended ascii characters like ▓ ▒ ░ into batch, but I am unable to save files with such characters

Use a better editor, then ;-) one which allows you to choose the target codepage.

Barring that, paste your characters into Notepad, Save-As with encoding set to Unicode, choose a name say "etc.txt". Then open a cmd prompt, "chcp 437" (replace "437" by the codepage you want), then "type etc.txt >etc-437.txt". At this point, "etc-437.txt" would be an 8-bit extended-ASCII text file saved in codepage 437.

However, I don't think that's the question you really meant to ask.

MrKnowItAllxx wrote:I don't know what chart online would tell me other characters like that which are interpreted as extended ascii characters in batch.

Batch files are 8-bit text, and all characters are interpreted. However, the _interpretation_ of character codes above 127 depends on the active codepage, because there is no single "extended ASCII" standard.

You can find the mappings for different codepages at http://msdn.microsoft.com/en-us/goglobal/bb964653, for example
- http://msdn.microsoft.com/en-us/goglobal/cc305156 (OEM 437);
- http://msdn.microsoft.com/en-us/goglobal/cc305145 (ANSI 1252).

MrKnowItAllxx wrote:Found what I need here: http://www.jimprice.com/jim-asc.shtml ... "Microsoft Windows ® has a different notion about what the high-order (upper 128) characters are"

That's not a bad summary, but it works better if one is already familiar with the 7-bit-ASCII vs 8-bit-extended matters, and the mechanics of Unicode mappings.

Liviu

Re: ASCII in batch

Posted: 03 Apr 2012 17:16
by MrKnowItAllxx
Thanks Liviu, I hadn't known anything about codepages or that you could change the codepage in cmd with "chcp xxx", definitely seems useful to know. Also, after a little while I figured out that I am able to type in the alt-codes for the characters I want directly in batch and output them to a file where they become practical nonsense but when I then "type" that file I get the original characters again.

And as for what I'm doing, I am simply creating a maze game, and want to use extended ascii characters to make the maps look more appealing.

Thanks for all the help :)

Re: ASCII in batch

Posted: 03 Apr 2012 22:51
by Liviu
MrKnowItAllxx wrote:Also, after a little while I figured out that I am able to type in the alt-codes for the characters I want directly in batch and output them to a file where they become practical nonsense but when I then "type" that file I get the original characters again.

Careful there ;-) The ALT-key input trick doesn't shield you from codepage pitfalls. Note that ALT+xyz is translated based on the default OEM codepage, while ALT+0xyz is taken as an ANSI code. The two do not necessarily result in the same character, see for example http://www.microsoft.com/resources/docu ... x?mfr=true.

Liviu

Re: ASCII in batch

Posted: 10 Apr 2012 14:57
by Cat
I'm a bit late for this, aren't I?

Use the alt code (█ = Alt + 219) using the number with a 0 in front of it. (Û = Alt + 0219)

Code: Select all

@echo off
echo Û
echo ±
echo °
pause