如何在批处理文件中回显 0x96 字符?

发布于 2024-10-10 04:14:11 字数 428 浏览 0 评论 0原文

我有一个 TFS 项目,其标题中包含 0x96 字符,例如“Project – X”我需要在批处理文件中引用它。问题是这个特定的破折号由 0x96(而不是 0x20)表示,它是 Unicode 中的控制字符(ASCII 中的 û?),因此以下内容(在 ANSI 编码的 .cmd 文件中)失败为“Project û X”。

echo "Project – X"

但是当直接粘贴到命令行时(我认为)它会作弊并将 0x96 转换为 0x20 (这不好,因为我的文件名不匹配)。我用十六进制编辑器尝试了这个,看起来好像有一些作弊行为。

如果 .cmd 文件编码为非 ANSI 格式,则该文件将无法工作。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一身骄傲 2024-10-17 04:14:11

默认情况下,cmd.exe 使用旧的“OEM”代码页,而 Unicode 之前的 Windows 应用程序使用“ANSI”代码页 (Windows 支持的代码页)。

您将(正如jeb提到的) 必须以 OEM 编码保存文本文件(假设字符在其中)或 将控制台切换为 ANSI 编码

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.

无法言说的痛 2024-10-17 04:14:11

像这样的东西有效

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

重要的是chcp 1252,chcp 850只是切换回我的默认代码页,但这不是必需的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文