📜 ⬆️ ⬇️

Heavy legacy of the past. Windows command line issues

Preface from the author, Rich Turner from Microsoft. This is an article about the command line: from its appearance and evolution to the Windows Console overhaul plans and the command line in future versions of Windows. Whether you are an experienced professional or a newcomer to IT, we hope that you will find the article interesting.

Once upon a time in a distant-distant server ...


From the first days of computer science development, people needed an efficient way to transfer commands and data to a computer and see the result of these commands / calculations.

One of the first truly effective man-machine interfaces was the Tele-Typewriter, or "TTY". This is an electromechanical machine with a keyboard for data input and some sort of output device - first a printer was used, later a screen.

Operator-entered characters are locally buffered and sent from a teletype to a neighboring computer or mainframe as a series of signals over an electrical cable (for example, RS-232) at a speed of 10 characters per second (110 baud bps):
')

Teletype Model 33 ASR

Note: David Gösswein maintains an excellent PDP-8 website , where you can find more information about the ASR33 (and the corresponding PDP-8 technology), including photos, videos, etc.

The program on the computer receives the entered characters, decides what to do with them, and, perhaps, asynchronously sends a response to the teletype. TTY can print / show operator received characters.

Then the technology improved, the transfer rate increased to 19,200 bps, and noisy and expensive printers replaced CRT displays (a widespread type of display in the 80s and 90s), as on the popular DEC VT100 terminal:


Terminal DEC VT100

Although the technology has improved, but this model - the terminal sends symbols to the program on the computer, and it gives the text to the user - has remained today as the fundamental model of the interaction of all command lines and consoles on all platforms!


Terminal and command line architecture

The model is elegant in its own way. One of the reasons is to preserve the simplicity and integrity of each component: the keyboard produces symbols that are buffered as electrical signals. The output device simply displays on the display (paper / screen) characters received from the computer.

At each stage in the system, only a stream of characters is transmitted, so this is a relatively simple process for implementing various communication infrastructures. For example, to add modems to transmit streams of input and output symbols over long distances via telephone lines.

Text encoding


It is important to remember that terminals and computers exchange data through streams of characters. When you press a key on the terminal keyboard, a value representing the character entered is sent to the connected computer. Press the 'A' key and the value 65 is sent (0x41). Press 'Z' and sends 90 (0x5a).

7-bit ASCII encoding


The list of characters and their meanings is defined in the American Standard Code for Information Interchange (ASCII) standard, which is also the ISO / IEC 646 / ECMA-6 standard - “7-bit coded character set”, which defines:



Standard 7-bit ASCII characters

When 7 bits are not enough: code pages


However, 7 bits do not provide enough space to encode many accents, punctuation marks, and symbols used in other languages ​​and regions. So with the addition of an extra bit, you can extend the ASCII character table with additional “code page” sets for characters 128–255 (and possibly redefining several non-printable ASCII characters).

For example, IBM introduced codepage 437 with several graphic characters like ╫ (215) and ╣ (185) and mathematical symbols, including π (227) and ± (241), and also redefined printable characters for commonly non-printing characters 1−31:


Codepage 437

The Latin-1 code page defines the set of characters used by Latin-based languages:


Latin-1 code page

In many command line environments and shells, you can change the current codepage so that the terminal displays different characters (depending on the fonts available), especially for characters with a value of 128–255. But an incorrectly specified code page will lead to the display of gibbering . And yes, “krakozyabry” is the real term ! Who would have thought? ;)

When 8 bits are not enough: Unicode


Code pages have temporarily solved the problem, but they have many shortcomings, for example, they do not allow displaying text from several code pages / languages ​​simultaneously. Thus, we had to introduce a new encoding that accurately displays each character and alphabet for all languages ​​known to humanity, leaving a lot of free space! Introducing Unicode .

Unicode is an international standard ( ISO / IEC 10646 ), which currently defines 137,439 characters from 146 modern and historical scripts, as well as many characters and glyphs, including numerous emoticons that are widely used in almost every application, platform, and device. Unicode is regularly updated with additional writing systems, new / corrected emoticons, symbols, etc.

Unicode also defines “non-printable” formatting characters, which allow, for example, to combine characters and / or affect previous or subsequent characters! This is especially useful in writing such as Arabic, where the ligature of a particular character is determined by others. Emoji can use a zero width joiner to combine multiple characters into one visual glyph. For example, Microsoft Emoji Ninja cat is formed by connecting the cat with other Emoji:


Emoji Cat Ninja Microsoft

When bytes are too many: UTF-8!


A unique and systematic representation of all characters requires a large amount of space, up to several bytes for each character.

Therefore, to save money, several new Unicode encodings were developed. Among the most popular are UTF-32 (4 bytes per character), UTF-16 / UCS-2 (2 bytes) and UTF-8 (1−4 bytes per character).

Largely due to backward compatibility with ASCII and saving space, UTF-8 has become the most popular Unicode encoding on the Internet. It has been showing explosive growth since 2008, when it overtook ASCII and other popular encodings in popularity:


The rise in popularity of the UTF-8 encoding (source: Wikipedia)

Thus, the terminals initially supported 7-bit and then 8-bit ANSI text, but most modern terminals support Unicode / UTF-8 text.

So, what is the command line and what is a 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 :


! .

?

, , , 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 … , , , !

?


, :


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 :


:



( ):


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 :


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, , , , , ! !

:


… !

, .

Source: https://habr.com/ru/post/417679/


All Articles