Re: Box-drawing characters in batch files...?
Posted: 09 Feb 2017 13:16
A Forum all about DOS Batch
esuhl wrote:and use the equivalent characters (accented E, etc.)
esuhl wrote:So... a computer won't necessarily support all valid code pages...?
aGerman wrote: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.
aGerman wrote: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).
esuhl wrote: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: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?
esuhl wrote: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?
esuhl wrote: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...? :-/
Code: Select all
reg Query HKCU\Console\%%SystemRoot%%_system32_cmd.exe /v FaceName>>temp.dat
for /f "usebackq skip=2 tokens=1,2,3* delims=" %%a in (temp.dat) do set valuereg=%%a
Del /f /q /a temp.dat >nul 2>&1
Rem ########### changing font ###########
if not "%valuereg%"=="Lucida Console" (
reg add HKCU\Console\%%SystemRoot%%_system32_cmd.exe /V ScreenColors /t REG_DWORD /d "0x0000000f" /f
reg add HKCU\Console\%%SystemRoot%%_system32_cmd.exe /V ScreenBufferSize /t REG_DWORD /d "0x00190050" /f
reg add HKCU\Console\%%SystemRoot%%_system32_cmd.exe /V FaceName /t REG_SZ /d "Lucida Console" /f
reg add HKCU\Console\%%SystemRoot%%_system32_cmd.exe /V FontSize /t REG_DWORD /d "0x000c0000" /f
reg add HKCU\Console\%%SystemRoot%%_system32_cmd.exe /V FontFamily /t REG_DWORD /d "0x00000036" /f
reg add HKCU\Console\%%SystemRoot%%_system32_cmd.exe /V FontWeight /t REG_DWORD /d "0x00000190" /f
echo.Draw boxes with single-frame characters.
echo.Draw boxes with double-frame characters.
echo.1st combination (single vertical, double horizontal frames).
echo.2nd combination (double vertical, single horizontal frames).
aGerman wrote:Some notes
1) You don't reset the registry updates which leads to permanent changes of the console settings.
2) The code doesn't display what it should because you don't use the right characters in the combinated single/double frames. (Compare it with my screenshot below, created with the code I provided in my first reply.)
3) It only works if the the ANSI codepage (used by your text editor) is set to Windows-1252.
Please read the whole thread to understand this behavior.
For anyone else puzzled why they don't see box characters in a file in Notepad++ (tested in v6.7.7) ensure you select menu Encoding|Character Sets|Western European|OEM-US to see box characters correctly. My Notepad++ was starting with default to character set TIS-620 yours most likely is set to "ANSI". Saving in "UTF-8" /" UTF-8 without BOM" or ANSI still preserves the file data OEM-US setting just means you can see it properly. If you use the "ASCII Panel" sidebar they will insert correctly but side bar (I guess displays in codepage 850) does not show them correctly in character column. Don't confuse this with the I never set it to that and have no idea why it selected Thai character set. You only have notice a difference when characters higher than ASCII 127 are in file.esuhl wrote: ↑04 Feb 2017 22:34But... I tried using Notepad++ and can paste and save a file with a box-character in it. The status bar shows that the file is encoded in UTF-8, but (unlike in Windows Notepad) the batch file saves and runs fine... except the box-characters echoed to the screen appear as capital accented characters. (The ones output to the text file appear fine.)