是否可以在 BAT 文件中使用扩展的 ASCII 字符? [英] Is it possible to use extened ASCII characters in a BAT file?

查看:34
本文介绍了是否可以在 BAT 文件中使用扩展的 ASCII 字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆动态创建的 *.BAT 文件.这些 BAT 文件用于在服务器中创建文件夹.每个BAT文件只有一行,如:MKDIRNetworkShareabc123

I have a bunch of dynamically created *.BAT files. These BAT files are used to create folders in a server. Just one line in each BAT file, such as: MKDIR NetworkShareabc123

这个abc123"字符串来自数据库.

This "abc123" string is from a database.

它可以按需创建数千个子文件夹运行一段时间,直到今天它停止创建具有关闭单引号"的特殊子文件夹(Alt + 0146 if从 dos 提示符键入)在字符串中.

It runs OK for a while to create thousands subfolders on demand until today it stopped creating a special subfolder which has a "close single quote" (Alt + 0146 if typing from dos prompt) in the string.

我做了一些研究,发现这个关闭单引号"是一个扩展的 ASCII 字符.它无法正确保存在 ANSI BAT 文件中(最终成为其他内容).我尝试了 UNICODE 和 UTF-8 BAT 文件,但它不起作用.

I did some research and found that this "close single quote" is an extended ASCII character. It can't be saved properly in ANSI BAT file (end up as something else). I tried UNICODE and UTF-8 BAT file, but it doesn't work.

唯一接近关闭的解决方案是我尝试了一个二进制编辑器来确保它是代码 146,但是代码 146 给了我 Æ (ALT-146) 而不是关闭单引号"(Alt +0146).

The only near-close solution is that I tried a binary editor to make sure it's code 146, but code 146 gives me Æ (ALT-146) not "close single quote" (Alt + 0146).

我知道我可以在 DOS 提示符下手动输入特殊字符(使用键盘 Alt + ).但是有没有办法在 BAT 文件中正确保存这个关闭单引号"(Alt + 0146),以便我可以动态执行它们?

I know I can manually type special characters in DOS prompt (by using keyboard Alt + ). But is there a way to properly save this "close single quote" (Alt + 0146) in BAT file so I can execute them dynamically?

主机系统是 Windows Server 2003 US-English.

The host system is Windows Server 2003 US-English.

推荐答案

感谢您使用 CHCP 65001 技巧.它会导致正确的解决方案:

Thank you for this CHCP 65001 trick. It leads to proper solution:

我采取了以下步骤来解决问题:

I took follow steps to resolve the issue:

++++++++++++++++++++

+++++++++++++++++++

准备 BAT 文本文件(手动或动态)

Prepare the BAT Text File (either manually or dynamically)

++++++++++++++++++++

+++++++++++++++++++

(1) 将第一行留空(这是必须的,因为UTF-8文本文件的第一行有隐藏字符)

(1) Make the first line blank (this is necessary, because there are hidden chars in the first line for UTF-8 text file)

(2) 将 CHCP 65001 作为第二行

(2) Put CHCP 65001 as second line

(3)这里的主线:MKDIR etworkshareabc(右单引号-->这是特殊的扩展ASCII字符)123

(3) main line here: MKDIR etworkshareabc(right single quote-->this is special extended ASCII char)123

(4) 确保BAT文件保存为UTF-8

(4) make sure the BAT file saved as UTF-8

++++++++++++++++++++

+++++++++++++++++++

现在是 CMD.EXE 技巧

Now it's the CMD.EXE trick

++++++++++++++++++++

+++++++++++++++++++

(1) 启动cmd.exe

(1) Start cmd.exe

(2)打开cmd.exe黑屏属性

(2) open cmd.exe black screen property

(3) 确保黑屏字体是true type",即TT"之类的.默认情况下,它是光栅字体,不能正确处理特殊的 ascii 代码.(这是关键步骤)

(3) make sure the black screen font is "true type" i.e. "TT" like. By default, it is raster font, can not handle special ascii code properly. (This is the key step)

(4) 现在我可以运行我的 BAT 来正确处理那些扩展的 ASCII 字符.

(4) now I can run my BAT to handle those extended ASCII chars properly.

这篇关于是否可以在 BAT 文件中使用扩展的 ASCII 字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆