5

This code:

   @echo off
   set /p a=Installing [<nul
   set b=1
   :loop
   if %b% leq 2 set /p a=°<nul
   if %b% gtr 4 if %b% leq 6 set /p a=±<nul
   if %b% gtr 6 if %b% leq 8 set /p a=²<nul
   if %b% gtr 8 if %b% leq 10 set /p a=±<nul
   if %b% gtr 10 set /p a=°<nul
   choice /t 1 /c y /d y>nul
   set /a b=%b%+1
   if %b%==13 (echo ]&goto :eof)
   goto :loop

... came from http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_1237-DOS-ECHO-text-to-previous-line-by-Paul-Tomasi.html#c18182 and produces the below output in a cmd window:

    Installing [░░▒▒▓▓▒▒░░]

However, I cant seem to find an explanation through google as to how this works. Substituting other extended ascii characters into their place seems to produce "The syntax of the command is incorrect", so have only managed to guess that this is a hack whereby something exchanges these characters to lower characters in the extended ascii set, by way of unintended-by-the-designers trick.

If anyone could also suggest a good website for learning more about cmd / cmd programs' features like this, it would be appreciated.

kamilk
  • 3,829
  • 1
  • 27
  • 40
user66001
  • 774
  • 1
  • 13
  • 36
  • Could ti be due to [the font that cmd is using?](http://stackoverflow.com/questions/1259084/what-encoding-code-page-is-cmd-exe-using) – acattle Dec 02 '12 at 02:28
  • Not really an answer, but still interesting: try running `type` on your batch file from the command line, as in `type mybatchfile.bat`. My text editor shows `±` and all the rest, but the `type` command shows `░` and the rest. Putting `░` in the batch file `type`s out as `ª`. The `edit` command-line editor shows the command-line characters too, rather than the Windows ones. Maybe a font thing, as acattle's link suggests. – user1201210 Dec 02 '12 at 02:41
  • @acattle - I have tried the three fonts available to me in cmd (Raster fonts, being the one the above results were based on; now also Consolas & Lucida Console); Consolas had a blank character for °, and both it and Lucida Console produced the command is incorrect error for the second ± (unusually). Given it is cmd and not a word processor (for example) would doubt there would be differing characters in the charset for each font, just different look of the same respective charset characters. – user66001 Dec 02 '12 at 02:41
  • @tenterhook - Thanks. Still holding out for someone who could explain why this is, though. – user66001 Dec 02 '12 at 02:42
  • Also, I am using Notepad to edit the batch file, and it is apparently using Lucida Console, so would think (if it was a font thing) it would be displaying the same as the console set to this font, no? – user66001 Dec 02 '12 at 02:50
  • And as to your question about tutorials teaching to write stuff like the one above - is there a particular reason why you're studying batch files? It's a rather obsolete technology, so unless you're targeting an old version of Windows (or DOS), I would recommend learning PowerShell instead. It's preinstalled in Windows 7 and above, Windows Server 2008 R2 and above, and versions for Windows XP, Vista and Server 2003 also exist, though you need to download them. PowerShell scripts are much easier to code and support Unicode, so this particular problem wouldn't exist there. – kamilk Dec 02 '12 at 11:48
  • @kamilk - Thanks for your suggestion, however I develop quick debugging solutions for some clients who use any version of Windows from 2000 up. So, like you say, I would have to get them to install PS on machines, just to run a simple set of commands. Then there is also the issue of explicitly allowing cmdlets to run, right? – user66001 Dec 02 '12 at 13:39

1 Answers1

4

It's because your editor uses a different encoding from the one DOS and the command line use.

See characters 176-178 here:

http://academic.evergreen.edu/projects/biophysics/technotes/program/ascii_ext-pc.htm

Character pairs in columns DOS and WIN are represented by the same numerical values, but DOS (and hence the command line) and Windows (your text editor) display these numbers as different symbols.

In case it's not clear: your text file is a series of bytes (numbers) and one of these bytes has value 176. Under DOS code page 437 it used to denote ▓ glyph, and command line, for historical reasons, uses the same encoding as DOS did. But your text editor, running on Windows, apparently reads the file using the old Windows-1252 encoding, where 176 means °.

You could try to find an editor supporting 437, it would save you from such confusions.

kamilk
  • 3,829
  • 1
  • 27
  • 40
  • Thanks @kamilk - I understand now. A couple of follow up questions, however - 1) Is there anyway to tell what programs (Like cmd.exe, and Notepad) are using in the way of code page? 2) I am guessing that fonts are tied to code pages, explaining how the same font used in the cmd window, was different to the same font in Notepad? and finally, 3) Any ideas on why I got "The syntax of the command is incorrect" when substituting one of those for ­­­≡­ (Which, for reasons I don't understand either, cannot seem to get by Alt+240, which gave me this to c&p in Notepad running on Win7) – user66001 Dec 02 '12 at 13:47
  • ...but gives me - on Notepad in WinXP) – user66001 Dec 02 '12 at 13:50
  • ATTN @kamilk - Happy to mark your correct answer as such, if you could address the additional questions for mine and others in the future's benefit. – user66001 Dec 03 '12 at 21:27
  • 1) I don't know of any, except for googling and guessing and checking settings of this program to see if it allows you to switch the encoding it uses (this applies to text editors only). 2) I don't really know how fonts work internally, but they're rather independent from fonts. Encoding is used to decide what character should be drawn, and fonts decide what shape this character will have. 3) Not really. The equivalent of this character should be ð, so if that's what you type and it doesn't work, then I've got no idea why. – kamilk Dec 03 '12 at 22:10