   『楼 主』:
[原创]Win2000/XP中的命令行[06-05-22]
使用 LLM 解释/回答一下
Win2000/XP中的命令行
Updated:2006-05-22
Windows2000/XP所缺省支持的命令行环境主要有两个:cmd.exe(以下简称CMD)和command.com(以下简称COMMAND),尽管它们许多方面与DOS很相似,但它们都不是DOS。它们只是操作系统Windows的外壳界面,而DOS(例如MS-DOS、FreeDOS等)则是独立的操作系统。
CMD是最常用的命令行环境,提供对系统中所有命令行程序的支持,包括32位PE格式的控制台程序和16位MZ格式的DOS程序;但它本身是一个32位的PE程序,所以在运行16位DOS程序前需要模拟一个环境,那就是“NT下的DOS虚拟机(NT Virtual DOS Machine,简称NTVDM)”,由%SystemRoot%\system32下的ntvdm.exe提供支持。因此,当我们刚刚打开CMD时,进程管理器中会显示出cmd.exe进程,而当在其中运行了一个16位的DOS程序后(比如debug),又会多出一个ntvdm.exe进程。
COMMAND是运行16位DOS程序的兼容性命令行环境,这个环境仍然由ntvdm.exe提供,而COMMAND不再是一个独立的“命令解释器”,而只是一个为了与低版本系统相兼容,而设计出的一个16位命令行环境的入口。所以,在运行COMMAND后,进程管理器只有一个ntvdm.exe进程,而不会有command.com进程。
CMD vs COMMAND
与COMMAND相比,CMD缺省提供了更多的命令行特性,比如多国语言显示和输入法(代码页)、更完善的字体(TrueType)、可以滚动浏览的窗口(屏幕缓冲区)、命令行历史记录和宏命令(DOSKEY)、文件和目录名自动完成、功能增强的内部命令(命令扩展)、实时更新的环境变量(延迟扩展)等等,这些特性在启动16位程序后将失效。
与CMD相比,COMMAND更像一个虚拟的PC机,许多运行16位程序所需要的硬件和软件环境都可以通过它模拟出来。它的启动过程与DOS相似,通过%SystemRoot%\system32\config.nt配置内存环境并加载所需要的硬件驱动,通过%SystemRoot%\system32\autoexec.nt执行某些启动虚拟环境时需要自动执行的任务。
命令行中的中文
Windows2000/XP简体中文版的CMD虽然缺省地支持中文代码页(936),但是这只是对32位程序而言;在使用了16位程序后,由于ntvdm.exe的影响,代码页会被强制切换回英文(437),因而不仅无法正常显示中文,并经常伴随着“Invalid keyboard code specified”的错误提示;而COMMAND则仅支持英文代码页,无法使用chcp进行代码页的切换。
解决这个问题的办法是graftabl.exe,这个启用在图形模式下显示扩展字符集的功能的工具,可以使16位程序处在英文代码页环境下仍然可以显示中文。
如果在CMD中,首先运行chcp 437将内部代码页切换为英文,再运行graftabl 936启用中文字符集显示,此后无论是否运行16位程序,则输出代码页均为中文,但此时仍无法使用中文输入法输入中文。
如果在COMMAND中,则内部代码页已为英文,可直接运行graftabl 936启用中文字符集显示,此时可在COMMAND中显示中文,但也无法输入中文。
如果在批处理脚本中,则预先写入chcp 437>nul和graftabl 936>nul两句,可以保证以后运行16位程序时正常地显示中文。
其它重要的命令行
“故障恢复控制台”是Windows2000/XP安装光盘上提供的命令行环境,主要用于修复系统故障的修复,缺省并不被安装到系统中。
“PowerShell”是下一代Windows的命令行工具,将是CMD的替代品,但目前仍没有列入到Windows2000/XP的缺省配置中,它需要.Net框架2.0的支持。
“微软管理规范命令行”提供了到 WMI 的简单接口,这样即可利用 WMI 管理运行 Microsoft Windows 的计算机,提供了命令行或脚本方式浏览和管理系统资源的便捷方式,它是WindowsXP所带来的新工具,第一次运行时会自动进行初始化安装配置。
相关的概念
命令行解释器(Command Processor/Command Interpreter)
命令行解释器是一个单独的软件程序,它可以在用户和操作系统之间提供直接的通讯。非图形命令行解释器用户界面提供运行基于字符的应用程序和实用程序的环境。命令行解释器通过使用类似于 MS-DOS 命令解释程序 command.com 的各个字符来执行程序并在屏幕上显示其输出。Windows 服务器操作系统(NT)命令行解释器使用命令解释程序 cmd.exe(该程序加载应用程序并指示应用程序之间的信息流动)将用户输入转换为操作系统可理解的形式。
命令提示符(Command Prompt)
1、命令行解释器cmd.exe的快捷方式,它可以打开一个CMD窗口,一般位于开始菜单的“附件”中;
2、命令行中输入每条命令前的提示文字,通常为当前所在路径信息,可以通过环境变量PROMPT来修改;
外壳/界面(Shell/Interface)
操作系统或其他系统中负责实现用户与系统内核交互的程序或模块。典型地,资源浏览器(explorer.exe)和命令行解释器(cmd.exe)都是Windows系统的外壳,前者是属于图形化界面(Graphic User Interface, GUI),后者则是命令行界面(Command Line Interface, CLI)。
控制台(Console)
1、对系统进行集约化控制和参数配置的环境。例如,图形界面的控制台有“微软管理控制台(Microsoft Management Console,MMC)”,命令行界面的有“命令行解释器(cmd)”和“微软管理规范命令行(wmic)”。
2、命令行环境下的输入输出设备,代号为con,它通常可以看作是键盘和屏幕的组合。
Last edited by willsort on 2006-5-22 at 15:03 ]
### Command Lines in Win2000/XP
Updated: 2006-05-22
The command line environments supported by default in Windows 2000/XP are mainly two: cmd.exe (hereinafter referred to as CMD) and command.com (hereinafter referred to as COMMAND). Although they are similar to DOS in many aspects, they are not DOS. They are just the shell interfaces of the Windows operating system, while DOS (such as MS-DOS, FreeDOS, etc.) is an independent operating system.
CMD is the most commonly used command line environment, providing support for all command line programs in the system, including 32-bit PE format console programs and 16-bit MZ format DOS programs; but it itself is a 32-bit PE program, so an environment needs to be simulated before running 16-bit DOS programs, that is, "NT Virtual DOS Machine (NT Virtual DOS Machine, referred to as NTVDM)", which is supported by ntvdm.exe in %SystemRoot%\system32. Therefore, when we just open CMD, the process manager will show the cmd.exe process, and when a 16-bit DOS program (such as debug) is run in it, an additional ntvdm.exe process will appear.
COMMAND is a compatibility command line environment for running 16-bit DOS programs. This environment is still provided by ntvdm.exe, and COMMAND is no longer an independent "command interpreter", but just an entry of a 16-bit command line environment designed to be compatible with low-version systems. Therefore, after running COMMAND, there is only one ntvdm.exe process in the process manager, and there will be no command.com process.
### CMD vs COMMAND
Compared with COMMAND, CMD provides more default command line features, such as multi-language display and input method (code page), more perfect fonts (TrueType), scrollable windows (screen buffer), command line history and macro commands (DOSKEY), automatic completion of file and directory names, enhanced internal commands (command extensions), real-time updated environment variables (delayed expansion), etc. These features will become invalid after starting 16-bit programs.
Compared with CMD, COMMAND is more like a virtual PC, and many hardware and software environments required for running 16-bit programs can be simulated through it. Its startup process is similar to DOS, configuring the memory environment through %SystemRoot%\system32\config.nt and loading the required hardware drivers, and executing some tasks that need to be automatically executed when starting the virtual environment through %SystemRoot%\system32\autoexec.nt.
### Chinese in the Command Line
Although the CMD in the Simplified Chinese version of Windows 2000/XP supports the Chinese code page (936) by default, this is only for 32-bit programs; after using 16-bit programs, due to the influence of ntvdm.exe, the code page will be forcibly switched back to English (437), so not only can Chinese not be displayed normally, but there are often error prompts of "Invalid keyboard code specified"; while COMMAND only supports the English code page and cannot use chcp to switch the code page.
The solution to this problem is graftabl.exe, a tool that enables the function of displaying extended character sets in graphic mode, which can make 16-bit programs still display Chinese in the English code page environment.
If in CMD, first run chcp 437 to switch the internal code page to English, then run graftabl 936 to enable the Chinese character set display, then no matter whether 16-bit programs are run or not, the output code page is Chinese, but at this time, Chinese input method cannot be used to input Chinese.
If in COMMAND, the internal code page is already English, you can directly run graftabl 936 to enable the Chinese character set display, at this time, Chinese can be displayed in COMMAND, but Chinese input cannot be made either.
If in a batch script, write chcp 437>nul and graftabl 936>nul in advance, which can ensure that Chinese is displayed normally when 16-bit programs are run later.
### Other Important Command Lines
"Recovery Console" is a command line environment provided on the Windows 2000/XP installation disc, mainly used for repairing system failures, and is not installed in the system by default.
"PowerShell" is a command line tool for the next generation of Windows and will be a replacement for CMD, but it is not currently included in the default configuration of Windows 2000/XP, and it requires the support of.Net Framework 2.0.
"Microsoft Management Console Command Line" provides a simple interface to WMI, so that you can use WMI to manage computers running Microsoft Windows, providing a convenient way to browse and manage system resources in command line or script mode. It is a new tool brought by Windows XP, and initialization installation configuration will be automatically carried out when it is run for the first time.
### Related Concepts
Command Processor/Command Interpreter
A separate software program that can provide direct communication between the user and the operating system. The non-graphic command line interpreter user interface provides an environment for running character-based applications and utilities. The command processor executes programs and displays their output on the screen by using various characters similar to the MS-DOS command interpreter command.com. The Windows server operating system (NT) command line interpreter uses the command interpreter cmd.exe (which loads applications and directs the flow of information between applications) to convert user input into a form that the operating system can understand.
Command Prompt
1. A shortcut of the command line interpreter cmd.exe, which can open a CMD window and is generally located in "Accessories" in the Start menu;
2. The prompt text before entering each command in the command line, usually the current path information, which can be modified through the environment variable PROMPT;
Shell/Interface
A program or module in the operating system or other systems responsible for realizing the interaction between the user and the system kernel. Typically, the resource explorer (explorer.exe) and the command line interpreter (cmd.exe) are both shells of the Windows system. The former belongs to the graphical user interface (Graphic User Interface, GUI), and the latter belongs to the command line interface (Command Line Interface, CLI).
Console
1. An environment for intensive control and parameter configuration of the system. For example, the console of the graphical interface is "Microsoft Management Console (Microsoft Management Console, MMC)", and the command line interface is "Command Line Interpreter (cmd)" and "Microsoft Management Console Command Line (wmic)".
2. An input and output device in the command line environment, code-named con, which can usually be regarded as a combination of a keyboard and a screen.
Last edited by willsort on 2006-5-22 at 15:03 ]
此帖被 +40 点积分 点击查看详情 评分人:【 redtek 】 | 分数: +2 | 时间:2006-11-6 23:14 | 评分人:【 pengfei 】 | 分数: +6 | 时间:2006-11-29 02:46 | 评分人:【 hxuan999 】 | 分数: +2 | 时间:2006-12-15 02:51 | 评分人:【 oilio 】 | 分数: +2 | 时间:2007-3-14 09:39 | 评分人:【 Billunique 】 | 分数: +2 | 时间:2007-3-28 00:53 | 评分人:【 crocodile 】 | 分数: +1 | 时间:2007-8-31 06:12 | 评分人:【 Kinglion 】 | 分数: +25 | 时间:2009-6-30 03:14 |
|
|