过去的严重遗产。 Windows命令行问题

Microsoft的前言Rich Richer,来自Microsoft。 本文是关于命令行的:从它的外观和演变到Windows控制台大修计划以及Windows未来版本中的命令行。 无论您是经验丰富的专业人员还是IT新手,我们都希望您觉得本文有趣。

很久很久以前,在遥远的服务器上...


从计算机科学发展的第一天开始,人们就需要一种有效的方法来将命令和数据传输到计算机,并查看这些命令/计算的结果。

Tele-Typewriter(电传打字机)是最早真正有效的人机界面之一。 这是一台机电设备,带有用于数据输入的键盘和某种输出设备-首先使用打印机,然后使用屏幕。

操作员输入的字符在本地进行缓冲,并通过电缆(例如RS-232)以每秒10个字符的速度(110波特,每秒比特,bps)从电传打字机以一系列信号的形式从电传打字机发送到相邻的计算机或大型机:


电传打字机型号33 ASR

注意:David Hesswaine拥有一个出色的PDP-8网站 ,您可以在其中找到有关ASR33 (和相关PDP-8技术)的更多信息 ,包括照片,视频等。

计算机上的程序接收输入的字符,决定如何处理它们,并有可能异步地向电传发送响应。 电传打字机可以打印/显示给操作员所接收的字符。

然后技术得到了改进,传输速度提高到19,200 bps,并且像在流行的DEC VT100终端上一样,用CRT显示器(在80年代和90年代广泛使用的显示器)代替了嘈杂而昂贵的打印机:


DEC VT100终端

尽管技术得到了改进,但是该模型-终端将字符发送到计算机上的程序,并向用户提供文本-至今仍然是所有平台上所有命令行和控制台交互的基本模型!


终端和命令行架构

该模型以其自己的方式优雅。 原因之一是每个组件的简单性和完整性:键盘产生的字符被缓冲为电信号。 输出设备仅在显示屏(纸张/屏幕)上显示从计算机接收到的字符。

在每个阶段,系统中仅传输字符流,因此这是用于实现各种通信基础结构的相对简单的过程。 例如,添加调制解调器以通过电话线长距离传输输入和输出字符流。

文字编码


重要的是要记住,终端和计算机通过字符流交换数据。 当在终端键盘上按下一个键时,代表输入字符的值将被发送到所连接的计算机。 按“ A”键-并发送值65(0x41)。 按“ Z”,然后发送90(0x5a)。

7位ASCII编码


字符列表及其含义在美国信息交换标准码(ASCII)中定义 ,又名ISO / IEC 646 / ECMA-6- “ 7位编码字符集”,它定义了:

  • 128个值代表印刷的拉丁字符A-Z(65-90),a-z(97-122),0-9(48-57)
  • 许多常见的标点符号
  • 几个不可打印的控制代码(0-31和127):


标准7位ASCII字符

当7位不足时:代码页


但是,7位不能提供足够的空间来编码其他语言和区域中使用的许多变音符号,标点符号和字符。 因此,通过增加一个额外的位,您可以使用128-255个字符的“代码页”的其他集合扩展ASCII字符表(并可能重新定义几个不可打印的ASCII字符)。

例如,IBM引入了代码页437,其中包含几个图形字符(例如╫(215)和╣(185))以及数学字符,包括π(227)和±(241),还为通常不可打印的字符1–31重新定义了可打印的字符:


第437页

Latin-1代码页定义了基于拉丁语的语言使用的字符集:


Latin-1代码页

在许多命令行环境和Shell中,您可以更改当前代码页,以便终端显示不同的字符(取决于可用的字体),尤其是对于值为128–255的字符。 但是,错误指定的代码页将导致显示错误。 是的,“ krakozyabry”是一个真实的名词 ! 谁会想到的? ;)

如果8位不够用:Unicode


代码页暂时解决了该问题,但是它们有很多缺点,例如,它们不允许同时显示几种代码页/语言中的文本。 因此,有必要引入一种新的编码,以准确显示人类已知的所有语言的每个字符和字母,从而留下大量的自由空间! Unicode简介。

Unicode是一种国际标准( ISO / IEC 10646 ),目前从146种现代和历史脚本中定义了137,439个字符,以及许多字符和标志符号,包括在几乎所有应用程序,平台和设备。 Unicode会定期使用其他书写系统,新的/更正的表情符号,符号等进行更新。

Unicode还定义了“不可打印的”格式字符,例如,这些字符允许组合字符和/或影响先前或随后的字符! 这在阿拉伯语等脚本中特别有用,其中特定符号的连字由其他人确定。 表情符号可以使用零宽度连接符将多个字符组合成一个视觉字形。 例如,Microsoft Ninja猫表情符号是通过将猫与其他表情符号连接而形成的:


微软猫忍者表情符号

当字节太多时:UTF-8!


所有字符的独特而系统的表示方式需要很大的空间,每个字符最多几个字节。

因此,为了节省资金,开发了几种新的Unicode编码。 其中最受欢迎的是UTF-32(每个字符4个字节),UTF-16 / UCS-2(2个字节)和UTF-8(每个字符1-4字节)。

很大程度上是由于与ASCII的向后兼容性和节省空间,UTF-8已成为Internet上最流行的Unicode编码。 自从2008年取代ASCII和其他流行的编码以来,它显示出爆炸性的增长:


UTF-8编码的日益普及(来源:Wikipedia)

因此,起初终端支持7位然后是8位ANSI文本,但是大多数现代终端都支持Unicode / UTF-8文本。

那么什么是命令行,什么是Shell?


« » CLI (/ ) , : CLI .

, echo Hello «Hello» (, ). dir (Cmd) ls (PowerShell/*NIX) ..

, . , , «» (shell).

Unix/Linux Unix (sh) , Korn shell (ksh), C shell (csh) Bourne Shell (sh). , Bourne Again Shell (bash) ..

Microsoft:


Windows, , , , /, .


« » (, Windows, Linux, macOS) (GUI). GUI / .


Cmd, PowerShell Ubuntu Linux WSL

, / , , - , .

, , : , , , () — . TTY Pseudo Teletype (PTY) .




, . , , . «» — , , *NIX.


: MS-DOS


. Unix, CP/M, DR-DOS . MS-DOS - IBM PC :


MS-DOS 6.0

, «» MS-DOS , batch- (.bat).

MS-DOS , ! Batch- , / , , ..

, , , . Windows!

, , . . , , - .

.


(GUI), Xerox Alto.

GUI Lisa Macintosh Apple, Commodore Amiga (Workbench), Atari ST (DRI GEM), Acorn Archimedes (Arthur/RISC OS), Sun Workstation, X11/X Windows , Microsoft Windows.

Windows 1.0 1985 MS-DOS, GUI , :


Windows 1.01 MS-DOS

Windows 2.x, 3.x, 95 98 MS-DOS. Windows MS-DOS Windows (, ), MS-DOS.

: Windows ME (Millennium Edition) . - MS-DOS Windows ( Gaming & Media). Windows 2000 (, TCP/IP), , NT.

Microsoft , MS-DOS Windows. .

Microsoft — Unix! , !


MS-DOS, Microsoft XenixUnix 7 — , Z8000, 8086/80286 68000.

1984 Xenix Microsoft Unix !

Bell Labs — Unix — AT&T, Unix System V .

Microsoft , . Xenix: 1987 Microsoft Xenix Santa Cruz Operation (SCO), Xenix .

Microsoft + IBM == OS/2…


1985 Microsoft IBM OS/2. « DOS» 32- CPU , IBM OEM.

OS/2 . 1990 Microsoft IBM . , IBM Microsoft, , Windows 3.1. IBM OS/2 2006 .

1988 Microsoft , , . , , .

Microsoft: Windows NT


1988 Microsoft , VAX/VMS DEC. — , , , Microsoft , .

Windows NT: , Windows 2000, Windows XP, Windows Vista, Windows 7, Windows 8 Windows 10, Windows Server, Windows Phone 7+, Xbox HoloLens!

Windows NT . Intel i860, MIPS R3000, Intel 80386+, DEC Alpha PowerPC. Windows NT IA64 Itanium, x64 ARM/ARM64, .

Windows NT Windows Console Command Prompt (cmd.exe). Cmd MS-DOS, .

PowerShell


Cmd Windows (, , ). — , Cmd . « » , «» MS-DOS Windows!

2000- Cmd : Microsoft . PowerShell ( « » ).

PowerShell — - , /, *NIX: PowerShell . ( sed/grep/awk/lex/.).

.NET Framework Common Language Runtime (CLR), PowerShell .NET , … … . :)

PowerShell, «PowerShell » (Manning Press), — PowerShell. , .

PowerShell Microsoft, Windows, Exchange Server, SQL Server, Azure . Windows / .

PowerShell Core — PowerShell , Windows Linux, BSD macOS.

POSIX NT, Interix UNIX


NT NT - .

1993 Windows NT 3.1, : Ѕ-DOS, Windows, OS/2 POSIX v1.2. , — !

POSIX Windows NT , . Microsoft Softway Systems POSIX- Interix NT. Interix , Services For Unix (SFU) Windows Server 2003 R2 Windows Vista. SFU Windows 8, , - .



Windows 10 — Windows!


Windows 10 UserVoice , . Microsoft :

  1. Windows
  2. Linux Windows

Microsoft :

  1. Windows Console , Windows Console
  2. Windows Subsystem for Linux (WSL)

, , !

Windows Linux (WSL)


GNU/Linux «» ( Linux ) , . Windows POSIX- , SFU Linux - Unix/POSIX.

Windows, Microsoft, , Windows Linux!

2014 Microsoft , Windows Linux (WSL). WSL Build 2016, Windows 10 Insider.

WSL Anniversary Update 2016 . , WSL: , Linux. ( !) WSL, Linux.

( 2018 ) WSL Linux, , , , .. , IT-, DevOps , , , Linux . ., Linux Windows , .

WSL WSL Linux, Windows.

Windows Console


2014 Windows Linux (WSL) , , Windows .

, , *NIX- , ANSI/VT, *NIX UI.

WSL, Linux?

, Windows 7 Windows 10: , Windows 7 () VT, tmux, htop, Midnight Commander cowsay, Windows 10 ():


Windows 7 Windows 10

, 2014 « Windows Console». , Windows Console… 28 — , , .

, - , , , . . Windows, , , , , , , « ». ;)

, . , 1−2% , Windows Build, … … « », .

, , , , , :

  1. , , . . ( )
  2. /IO ( )

Windows Console :


    • , , .. STL
    • , ( ), « »
  • ANSI/VT, *NIX
  • 24- 16 !
  • : Narrator
  • /

! .

?

, , , Microsoft.

Microsoft , // .

Microsoft Windows, , , !

MS-DOS, Unix, OS/2 Windows , , . , , ! Visual Studio (VS) . Exchange Server SQL Server PowerShell .

Windows Console


Windows NT 1989 , . , MS-DOS. Windows, GUI — Windows Console! Windows NT , , Windows, - !

Windows ( 2018 ) 30 … , , , !

?


, :


    • , , , .
    • / ANSI/VT
    • //
  • :
    • /
    • , (, , , ..)
  • :
    • / / ..

Windows :

Windows Console


Windows — Win32. C, C++ , .

: , Windows C C++. : - NT, , Windows C! ? C++ . C++ , 1990-, $60/ (… $60 !), vtables . , C++. , C++ . , , … C++!

Windows?


Windows 7 Windows Client Server Runtime Subsystem (CSRSS)! Windows 7 CSRSS :

  • conhost.exe — Windows UX
  • condrv.sys — Windows, conhost //

:



( ):

  • ConDrv.sys
  • ConHost.exe — Win32 GUI:
    • ConHost Core
      • API: IOCTL, , API
      • API: API Win32 ,
      • : ,
      • VT Parser: , VT, API
      • : , . , 2D- CHAR_INFO, ( )
      • : / / ..
    • Console UX App Services — UX UI

Windows Console API


, NIX, / API / IO Control (IOCTL), ! ANSI/VT ( Linux), , API!

*NIX Windows: *NIX « », Windows « »!

, , . , Windows *NIX!

*NIX


Unix 1960- 1970- , , ( ) . : , .

: *NIX, / , , «» , .

, Linux , /proc/cpuinfo:



: / , sed, awk, perl, python .. , , . , — , / , , , .

Windows


Windows NT, «» : «-» , : Simula Smalltalk , C++ . - , Python, Eiffel, Objective-C, ObjectPascal/Delphi, Java, C# .

. , - ( 1989 ) Windows NT , « ». NT !

Windows NT Win32 API / . Win32 API , *NIX, . , , , . , .

, Windows: NT «», *NIX :

  • Console API: , ANSI/VT-, , Windows API
  • : (, , ), Console API

Windows


API , API , .

Windows


Console API.

? Windows.

, (, ..), Windows *NIX .

- Windows , , . , Windows , , .., *NIX — .

: Windows bash iTerm2 — , Windows Cmd/PowerShell.

, Cygwin, GNU Windows, , Linux. , Ruby, Python, Node Linux / *NIX.

, Microsoft Windows, Linux Windows Linux (WSL). WSL Linux , apt/zypper/npm/gem/. Linux Windows.

, , : , Windows Console command-history command-alias, ( ) .


, , . : //. / .

*NIX- , /. - (TTY, PTY ..), .

Windows API , . . API ? , Console API, Mac Linux?!

, , .

… !


*NIX , . /. Pseudo TTY (PTY).

Windows : Windows (conhost.exe) — , , Cmd.exe, PowerShell.exe, wsl.exe . Windows ( ) .

#SAYWHATNOW?

, Windows , .

, Windows .exe . Windows , .

: , « ». , ! Win32. . , « / ». !

, ? … . :

  1. IOCTL ,
  2. Windows , ConHost.exe — ,
  3. Windows «» (pipes),

. Windows? / , , ?

, . Windows (, ConEmu/Cmder, Console2/ConsoleZ, Hyper, Visual Studio Code, OpenSSH . .), , !

, , , (-32000, -32000). , — !

- , ?! , — .

, . .

Windows Console VT


, Windows API. Console API , , .. API ANSI/VT, .

, Windows 10 Windows ANSI/VT:



2014 , Microsoft Windows Console. ANSI/VT *NIX, Windows Linux (WSL) *NIX.

Windows 10 ANSI/VT, Windows Linux.

VT , GitHub. ;)


, Windows API !

Windows ( ) UCS-2 . 65536  ,  0 (Basic Multilingual Plane, BMP).

Console API. , : / , W (wchar)/ .

, WriteConsoleOutputCharacter WriteConsoleOutputCharacterA() ASCII WriteConsoleOutputCharacterW() . ...A ...W, .

: W API UCS-2, , A/W, , . W API UTF-16 .

W API UTF-16, UCS-2.

, , (zero width joiner), , .

- / ? , !

API ( NinjaCat 8 !), UCS-2 . , GDI- , !

… legacy-.

— . !

, ?


, , , — Windows, , , , , ! !

:

  • Windows:
    • Condrv.sys —
    • ConHost. — UX :
      • API — API IOCTL, /
      • API —
      • — , , , /
      • VT — ANSI/VT API
      • UX — UI , ,
      • — , .

  • *NIX
    • NIX: « / »
    • Windows: « , API»

    • API , IOCTL
    • API Windows
      • / Windows
    • Windows API
      • Windows
    • IOCTL « »
      • -Windows
    • Windows «»
      • ConHost.exe
      • ,
    • Windows ANSI/VT
      • Windows 10
    • UTF-8 ,

… !

, .

Source: https://habr.com/ru/post/zh-CN417679/


All Articles