Hmm. I'm afraid you didn't fully understand.
esuhl wrote:and use the equivalent characters (accented E, etc.)
This isn't portable. See the difference between Antonio's and Saso's examples. Both are able to write box-drawing characters for their specific computer settings. As I wrote, as soon as you have characters in the code that exceed the ASCII range it won't be portable anymore.
Ah. Thanks for correcting me. I've re-read this thread several times, but I still don't quite understand why this wouldn't work.
Going back to your example, let's say I want to echo the õ
character to screen. Notepad on your system uses a different encoding, so you enter the character as ä
, but doing chcp 850
will (I thought) make sure the character appears correctly on all systems...?
So long as the batch file contains byte E4, and the console is set to chcp 850... I don't understand why this wouldn't work...? (Other than the console font not having such a character.)
esuhl wrote:So... a computer won't necessarily support all valid code pages...?
Right. And fonts won't support all possible characters (I'm aware of only one project were developers try to achieve this).
It's important to understand the difference between files-charset vs. window-font.
A file consists of bits and bytes. You need a translation between the bytes read (or written) and the characters that shall be represented by these bytes. The charset (code page) is just the rule for this translation.
A window needs a font for graphically displaying these characters. Even if the translation of the bytes read succeed the characters can't be displayed if the font don't support them (that's what happened to Saso).
Yes -- I understand that, at least. That sounds like the final word on this, then! So it is literally impossible to guarantee that anything other than 7-bit ASCII characters will appear on screen correctly?
I thought the solution in your first reply might work. But is sounds like this needs a known font to be specified. And it looks like you can't do this from within a batch file.
But... my solution of writing the batch file in UTF-8 without a BOM to echo UTF-8 characters to a text file is pretty reliable, right?
It's a long-shot, but... Would there be any way to get a batch file to open a new console window with a specific font and code-page, and then re-direct commands to that window, thus guaranteeing that the first solution you posted would work every time...? :-/
I guess I might just have to make do with ASCII on screen!
Thanks again for everyone's really helpful replies. I feel like I've learned so much!