How is the echo symbol 0x96 in a batch file?

I have a TFS project with type 0x96 in its name, for example. "Project - X", which I need to specify in the batch file. The problem is that this particular dash is represented by 0x96 (rather than 0x20), which is the control character in Unicode (û in ASCII?), So the following (in the ANSI-encoded .cmd file) fails as "Project û X" .

echo "Project – X"

But when you inserted directly into the command line (I think), it cheats and translates 0x96 to 0x20 (which is not good, since my file names do not match). I tried this with a hex editor, and it looks like cheating is happening there.

A .cmd file will not work if it is encoded as nothing but ANSI.

+3
source share
2 answers

Something like this works

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

It is important that chcp 1252 , chcp 850 should only return to my default code page, but this is not necessary.

+2
source

By default, cmd.exe uses the old "OEM" code pages, while applications prior to Unicode Windows use the "ANSI" ( Code pages supported by Windows ) code pages .

You will ( like jeb alludes ) either have to save your text file in the OEM-encoding (provided that it has a character), or switch the console in ANSI encoding.

+3
source

Source: https://habr.com/ru/post/1783424/


All Articles