如何在批处理文件中回显 0x96 字符?
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
默认情况下,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.
像这样的东西有效
重要的是chcp 1252,chcp 850只是切换回我的默认代码页,但这不是必需的。
Something like this works
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.