在批处理脚本中框出图形字符(Windows CMD) [英] Box drawing characters in batch scripts (Windows CMD)

查看:178
本文介绍了在批处理脚本中框出图形字符(Windows CMD)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在旨在在Windows CMD环境(XP,7、8和reactOS)上运行的批处理脚本中显示框字符(单行或双行).这些用于框"的符号在代码页1252中指定.

I would like to display box characters (single o double line)in batch scripts that are aim to run on Windows CMD environments (XP,7,8 and reactOS). These symbols for "boxes" are specified in code page 1252.

我从脚本中使用CHCP命令设置必要的代码850或437.

From script I am setting the necessary code 850 or 437 with CHCP command.

chcp 437

chcp 437

我正在使用ECHO命令进行写操作

for writing I am Using ECHO command

ECHO要显示的字符"

ECHO "char to display"

我应该使用哪种文件编码(ANSI,UTF8等)?

What file encoding should i use (ANSI, UTF8,..)?

推荐答案

打开命令提示符 ,不带任何参数运行chcp(更改代码页),并且Windows命令处理器根据为执行批处理文件所使用的用户帐户配置的国家/地区解释批处理文件时,输出cmd.exe期望的字符编码的代码页.

Open a command prompt, run chcp (change code page) without any parameter and the Windows command processor outputs the code page of the character encoding expected by cmd.exe on interpreting a batch file according to country configured for the user account used to execute the batch file.

但是,在批处理文件使用命令echo输出字符之前,可以使用例如chcp 437 >nul显式设置代码页437.在这种情况下,应使用代码页对批处理文件中的所有字符进行编码.北美国家/地区(美国加拿大)默认使用代码页437,因此,Windows控制台窗口默认使用的所有字体均支持此代码页.

However, it is possible to use for example chcp 437 >nul to set explicitly the code page 437 before the batch file outputs characters with command echo. In this case all characters in the batch file should be encoded with using code page 437. Code page 437 is used by default in North American countries (Canada, USA) and for that reason supported by all fonts used by default for Windows console windows.

用于Windows控制台的另一个非常常见的代码页是代码页850 与代码类似页437,但是与代码页437相比,框图字符较少.默认情况下,此代码页在西欧国家/地区使用. Windows控制台窗口默认使用的所有字体也支持此功能.

Another very common code page used for Windows console is code page 850 being similar to code page 437, but has less box drawing characters in comparison to code page 437. This code page is used by default in Western European countries. It is also supported by all fonts used by default for Windows console windows.

参考的两个有关代码页437和850的Wikipedia页面显示了箱形​​图字符以及它们的十进制和十六进制代码值,这些字符编码为每个字符一个字节,即使用"ANSI"编码. "ANSI"在这里并不是一个正确的术语,因为代码页437和850是 OEM代码页尚未被美国国家标准协会(a)标准化.但是Microsoft对所有字符编码使用了ANSI一词,每个字符仅使用一个字节.

The two referenced Wikipedia pages about the code pages 437 and 850 show the box drawing characters and their decimal and hexadecimal code values on being encoded with one byte per character, i.e. using "ANSI" encoding. "ANSI" is not really a correct term here because the code pages 437 and 850 are OEM code pages which are not standardized by the American National Standards Institute (ANSI). But Microsoft used the term ANSI for all charater encodings using just one byte per character.

有关批处理文件使用UTF-8编码的情况,有关代码页437和850的Wikipedia页面还显示Unicode代码值.但是请注意,Windows控制台窗口默认使用的某些字体,例如Windows 7默认使用的 Terminal (光栅字体),不支持UTF-8编码.有关详细信息,请参见在为他人制作的批处理文件中使用另一种语言(代码页)的答案以及答案下方的注释

The Wikipedia pages about the code pages 437 and 850 show also the Unicode code value in case of UTF-8 encoding is used for the batch file. But please be aware that some fonts used by default for Windows console window like Terminal (raster font) used by default on Windows 7 does not support UTF-8 encoding. For details see my answer on Using another language (code page) in a batch file made for others and the comments below the answer.

我建议对带有echo命令行的批处理文件使用"ANSI"或更精确的OEM字符编码,这些命令行将输出使用代码页437编码的箱形绘图字符.

I recommend to use "ANSI" or more precise OEM character encoding for the batch file with echo command lines which output box drawing characters encoded with code page 437.

Windows GUI文本编辑器默认为北美和西欧国家/地区使用的"ANSI"编码为

The "ANSI" encoding used by default by Windows GUI text editors for countries in North America and Western Europe is Windows-1252. This could be important to know if the used text editor does not support displaying the batch file content with interpreting the bytes using code page 437 and for that reason it is necessary to enter the Windows-1252 characters with the code values which result in displaying the box drawing characters on being interpreted with OEM code page 437.

诸如UltraEdit之类的某些编辑器支持在每个代码页的每个字符编码的文本文件中显示一个字节,只要配置的字体也支持该代码页即可.

Some editors like UltraEdit support displaying a one byte per character encoded text file with any code page as long as the configured font supports also this code page.

终端字体绝对是写批处理文件中的文本编辑器字体的不错选择,该批处理文件应输出箱形图字符.

The font Terminal is definitely a good choice as text editor font on writing a batch file which should output box drawing characters.

示例:

批处理文件包含以下命令行OEM(使用代码页437编码):

A batch file contains following command lines OEM encoded with code page 437:

@echo off
%SystemRoot%\System32\chcp.com 437 >nul
echo ┌───────────────┐
echo │ box drawing 1 │
echo └───────────────┘
echo/
echo ╔═══════════════╗
echo ║ box drawing 2 ║
echo ╚═══════════════╝

此批处理文件包含以下字节(偏移量:十六进制字节; ASCII表示形式):

This batch file contains following bytes (offset: hexadecimal bytes ; ASCII representation):

0000h: 40 65 63 68 6F 20 6F 66 66 0D 0A 25 53 79 73 74 ; @echo off..%Syst
0010h: 65 6D 52 6F 6F 74 25 5C 53 79 73 74 65 6D 33 32 ; emRoot%\System32
0020h: 5C 63 68 63 70 2E 63 6F 6D 20 34 33 37 20 3E 6E ; \chcp.com 437 >n
0030h: 75 6C 0D 0A 65 63 68 6F 20 DA C4 C4 C4 C4 C4 C4 ; ul..echo ÚÄÄÄÄÄÄ
0040h: C4 C4 C4 C4 C4 C4 C4 C4 C4 BF 0D 0A 65 63 68 6F ; ÄÄÄÄÄÄÄÄÄ¿..echo
0050h: 20 B3 20 62 6F 78 20 64 72 61 77 69 6E 67 20 31 ;  ³ box drawing 1
0060h: 20 B3 0D 0A 65 63 68 6F 20 C0 C4 C4 C4 C4 C4 C4 ;  ³..echo ÀÄÄÄÄÄÄ
0070h: C4 C4 C4 C4 C4 C4 C4 C4 C4 D9 0D 0A 65 63 68 6F ; ÄÄÄÄÄÄÄÄÄÙ..echo
0080h: 2F 0D 0A 65 63 68 6F 20 C9 CD CD CD CD CD CD CD ; /..echo ÉÍÍÍÍÍÍÍ
0090h: CD CD CD CD CD CD CD CD BB 0D 0A 65 63 68 6F 20 ; ÍÍÍÍÍÍÍÍ»..echo 
00a0h: BA 20 62 6F 78 20 64 72 61 77 69 6E 67 20 32 20 ; º box drawing 2 
00b0h: BA 0D 0A 65 63 68 6F 20 C8 CD CD CD CD CD CD CD ; º..echo ÈÍÍÍÍÍÍÍ
00c0h: CD CD CD CD CD CD CD CD BC 0D 0A                ; ÍÍÍÍÍÍÍͼ..

字节的ASCII表示使用代码页Windows-1252.因此,可以在这里看到相同的字节值如何仅由于使用"ANSI"编码文本文件的不同代码页而导致显示不同的字符.

The ASCII representation of the bytes use code page Windows-1252. So it can be seen here how same byte value can result in a different character being displayed just because of using a different code page of "ANSI" encoded text file.

同一批处理文件将包含不带字节顺序标记的UTF-8编码:

The same batch file would contain UTF-8 encoded without byte order mark:

0000h: 40 65 63 68 6F 20 6F 66 66 0D 0A 25 53 79 73 74
0010h: 65 6D 52 6F 6F 74 25 5C 53 79 73 74 65 6D 33 32
0020h: 5C 63 68 63 70 2E 63 6F 6D 20 34 33 37 20 3E 6E
0030h: 75 6C 0D 0A 65 63 68 6F 20 E2 94 8C E2 94 80 E2
0040h: 94 80 E2 94 80 E2 94 80 E2 94 80 E2 94 80 E2 94
0050h: 80 E2 94 80 E2 94 80 E2 94 80 E2 94 80 E2 94 80
0060h: E2 94 80 E2 94 80 E2 94 80 E2 94 90 0D 0A 65 63
0070h: 68 6F 20 E2 94 82 20 62 6F 78 20 64 72 61 77 69
0080h: 6E 67 20 31 20 E2 94 82 0D 0A 65 63 68 6F 20 E2
0090h: 94 94 E2 94 80 E2 94 80 E2 94 80 E2 94 80 E2 94
00a0h: 80 E2 94 80 E2 94 80 E2 94 80 E2 94 80 E2 94 80
00b0h: E2 94 80 E2 94 80 E2 94 80 E2 94 80 E2 94 80 E2
00c0h: 94 98 0D 0A 65 63 68 6F 2F 0D 0A 65 63 68 6F 20
00d0h: E2 95 94 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2
00e0h: 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95
00f0h: 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90
0100h: E2 95 97 0D 0A 65 63 68 6F 20 E2 95 91 20 62 6F
0110h: 78 20 64 72 61 77 69 6E 67 20 32 20 E2 95 91 0D
0120h: 0A 65 63 68 6F 20 E2 95 9A E2 95 90 E2 95 90 E2
0130h: 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95
0140h: 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90 E2 95 90
0150h: E2 95 90 E2 95 90 E2 95 9D 0D 0A

注意:您的浏览器用于显示上述批处理文件代码的字体可能会导致两个框未显示为真正的封闭框,其全部六行宽度与Windows XP和Windows 7的Windows控制台窗口,其默认栅格字体或字体 Lucida Console (默认情况下在Windows控制台窗口的属性中也可用). Lucida Console 支持的字符比 Terminal 多得多,但这不是控制台窗口的默认字体.

Note: The font used by your browser to display the batch file code above could result in getting the two boxes not displayed as real closed boxes with same width on all six lines as it does in a Windows console window of Windows XP and Windows 7 with default raster font or with font Lucida Console which is by default also available in properties of a Windows console window. Lucida Console supports much more characters than Terminal, but it is not the default font for console windows.

文本编辑器UltraEdit具有一个 ASCII Table 视图,可以为其设置 Terminal 字体,该字体是OEM字体.这样可以很容易地输入方框图字符,这些字符在 ASCII表视图中以 Terminal 字体显示,并且可以通过双击这些字符将其插入批处理文件中.在视图中.

The text editor UltraEdit has an ASCII Table view for which the font Terminal can be set which is an OEM font. This makes it very easy to enter the box drawing characters which are displayed in ASCII Table view with font Terminal and which can be inserted into the batch file with double clicking on these characters in the view.

这篇关于在批处理脚本中框出图形字符(Windows CMD)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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