0

I have problems controlling character code pages in a Windows cmd window, or rather in DOS scripts (.bat files) I use for certain tasks on my Windows 7 office computer.

Here is the problem:

One of my scripts is used to open certain files in their respective programmes, e.g.

C:\Stuff\Büroeinrichtung\MyFile.xlsx

The crucial thing here is the u-umlaut (ü) in the directory name.

In my script I use

Start "" "C:\Stuff\Büroeinrichtung\MyFile.xlsx"

to start Excel and open the file.

This works as long as I tell my text editor (Notepad++) to encode the script using codepage 850 (Western European), as this is what the cmd windows on my machine use by default.

However, I want to be able to use scripts that are encoded in something else, primarily UTF-8 or UTF-8-BOM. From answers to another question posted here I learned that principally I can set a command in the script for the cmd window to change the codepage, e.g. chcp 65001 for UTF-8. So my script would then look like

chcp 65001
pause      :: this is here just to have some visual control while testing
Start "" "C:\Stuff\Büroeinrichtung\MyFile.xlsx"
pause      :: dito

But: whatever I do, I do not get this running. The cmd window nicely accepts the change to the codepage, then stops due to pause (in Line 2), but on hitting "enter" to continue I

  • either get an alert that something is wrong with the ü (other, fancy, characters displayed), or
  • I get an alert that a directory of that name wasn't found (again obviously something wrong with the ü the actual bits of which seem to respresent something else) or
  • the cmd window just disappears (apparently crashed, and apparently never reaching Line 4 where a new pause would halt it).

I tried all possible combinations of codepages called in the script and various encodings for the script file (.bat) itself but did not get anywhere.

So, to put the long story short: What do I have to do, in a script encoded in UTF-8 (or so) and going to be run on a machine using codepage 850 by default that a character ü (u-umlaut) in a directory name is to be understood in the script as exactly ü, nothing else?

  • If that's your entire code, the command prompt "disappears" because the script ended. To see if there are any errors, open the command prompt and run the script from there instead of double-clicking it. – SomethingDark May 31 '17 at 14:53
  • Your script is CHanging CodePage but you may have to use a True Type font which contains the characters you need, _(I think Raster Fonts is the default hence your issue)_. – Compo May 31 '17 at 15:15
  • @SomethingDark: I put the *pause* there in Line 4 exactly to stop it from disappearing. It should stop there and disappear only after I hit the Return key. The strange thing is that it disappears after (or during?) execution of Line 3. - Or where is the mistake in my thinking? – Christian Geiselmann May 31 '17 at 15:29
  • You clearly stated in your question that the prompt disappears _after_ you press enter to continue. – SomethingDark May 31 '17 at 15:53
  • @Something Dark: I meant hitting Return after the *pause* in Line 2, not after the *pause* in Line 4. I now edited the question to avoid this misunderstanding. – Christian Geiselmann May 31 '17 at 16:12
  • Have you tried codepage 437? – aschipfl May 31 '17 at 18:28
  • @aschipfl: I did right now (encoding of the .bat: set to UTF-8; codepage called in the script: 437). Result is, as in other cases: script tries to access the file but does not find it because where the ü is expected some fancy lines are in the string. – Christian Geiselmann May 31 '17 at 19:53

0 Answers0