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

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

问题描述

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

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 \NetworkShare\abc\123

此"abc \ 123"字符串来自数据库.

This "abc\123" string is from a database.

运行一会儿可以按需创建数千个子文件夹,直到今天它停止创建一个特殊的子文件夹,该子文件夹具有闭合单引号"( Alt + 0146 在字符串中从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美国英语.

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 \ networkshare \ abc(右单引号->这是特殊的扩展ASCII字符)\ 123

(3) main line here: MKDIR \networkshare\abc(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天全站免登陆