3

I've got a TFS project with a 0x96 character in its title, e.g. "Project – X" which I need to reference in a batch file. The problem is that this particular dash is represented by 0x96 (and not 0x20) which is a control character in Unicode (û in ASCII?), so the following (in an ANSI encoded .cmd file) fails as "Project û X".

echo "Project – X"

But when pasted straight to the command line (I think) it cheats and translates the 0x96 to a 0x20 (which is no good as my file names don't match). I tried this with a hex editor and it looks like there's some cheating going on.

The .cmd file won't work if it's encoded as anything but ANSI.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
timB33
  • 1,977
  • 16
  • 33

2 Answers2

4

By default, cmd.exe uses the old "OEM" codepages whereas pre-Unicode Windows applications use the "ANSI" codepages (Code Pages Supported by Windows).

You will (as jeb alludes) either have to save your text file in the OEM encoding (assuming that character is even in it) or switch your console to the ANSI encoding.

Community
  • 1
  • 1
McDowell
  • 107,573
  • 31
  • 204
  • 267
2

Something like this works

@echo off
SETLOCAL EnableDelayedExpansion
chcp 1252
set "name=Projekt û X.txt"
chcp 850
type "!name!"

The important thing is the chcp 1252, the chcp 850 is only to switch back to my default code page, but it is not neccessary.

jeb
  • 78,592
  • 17
  • 171
  • 225