开发者

Batch : encoding hell

开发者 https://www.devze.com 2023-01-29 10:02 出处:网络
In DOS batch, I have to read file paths from a file encoded in UTF-8. chcp 65001 :: read my file... Now all messages displayed in my script are broken (accentuated characters appear wrong). So I gu

In DOS batch, I have to read file paths from a file encoded in UTF-8.

chcp 65001
:: read my file...

Now all messages displayed in my script are broken (accentuated characters appear wrong). So I guess I must revert to the 开发者_Go百科previous chcp value.

When I call chcp all by itself, it spits me a nasty line, while all I want is the number :

C:...>chcp
Page de codes active : 850

How can I save the current codepage value in a variable before changing, so that I can set back to it after having read my file, and thus have my messages displayed in the console appear fine ?


for /f "tokens=2 delims=:" %a in ('chcp') do set OLDCP=%a
set OLDCP=%OLDCP:~1%

The second line removes the space before the number. Not actually needed, but I try keeping my values clean.

0

精彩评论

暂无评论...
验证码 换一张
取 消