Software

Inside the updated Windows Console

Microsoft's command line goes back to the future.

windows-consoleapps.jpg

Cmd, PowerShell, and Ubuntu Linux on WSL (Windows Subsystem for Linux), attached to independent Console instances.

Image: Microsoft

For all the work that's gone into graphical user interfaces over the years, the command line is still very much alive. You may not use it for your day-to-day work in Windows, but if you're a developer or a system administrator, or even work in devops, then it's a key element of everything you're doing.

We're all familiar with cmd.exe, the Windows command line. It's part of the heritage of Windows, building on the tools that shipped with DOS. While commands still have many of the same names, and many DOS apps will still run in the Windows console, it's a long way removed from that old text-mode DOS prompt, building on the evolution of the Windows platform. Over the years it's been joined in the Windows console by PowerShell, the default system administration scripting language for Windows and Windows Server, with tools for remote management of both Office 365 and Azure.

PowerShell's blue console and color-coded command strings are a long way removed from the old black-and-white DOS window. Its action-oriented command vocabulary is also very different, letting you get and set system settings, building actions into complex scripts that can manage whole fleets of servers. If the Windows command line is a tool for working with a single PC, then PowerShell is a sysadmin's Swiss Army knife for an entire organization full of PCs and servers.

Windows 10 recently brought along a third command-line environment — Linux — thanks to the Windows Subsystem for Linux. By providing a way to run native Linux binaries on Windows, the console is now the host for the familiar Bash scripting environment, handling Linux variants from Suse, Canonical, Debian, and the security-focused Kali.

That's all led to a considerable revamp for what was one of the oldest Windows apps, developed nearly 30 years ago for the original release of Windows NT. For many years it's been a simple command-line host, with basic support for cut and paste and a simple history. You could choose the color and font for your commands, and tweak the size and number of characters on-screen — usually some variant of the old, familiar VT100 80-column displays that used to be how we connected to shared computers.

SEE: Windows 10 April 2018 Update: An insider's guide (free PDF) (TechRepublic)

Modern terminal applications do a lot more than those old green and amber-screen devices. They're able to give us a history of the commands we've used, so we can quickly repeat them, or extract them to use as the basis for future scripts. They're also customisable, able to choose not only colors and columns, but also add keyboard shortcuts and integrate with the other tools we use. Multiple console windows can be terminals on remote systems, or can be running several different environments locally.

The original Windows console remained much the same from its introduction until the release of Windows 10. While PowerShell added color-coded command parsing, it was still much the same set of buffers that sat between the various command shells. Even the bugs were the same, as some companies were running commands that depended on those bugs! It was getting harder for Microsoft to change its command-line tooling, and third-party terminal apps were quickly getting user and developer attention — as were the more UNIX-oriented macOS and various Linux distributions.

Windows 10: an opportunity

Windows 10 provided Microsoft with an opportunity to completely rework its command-line tooling. As the OS itself was designed to be updated regularly, the console team would be able to push out updates, using the Insider program to test new features. In the background the same team had started work on supporting Linux on Windows, and it needed a console that would render Linux console user interfaces correctly. It also needed to deliver those new features in a tool that wouldn't break millions of existing scripts that were in use across the world.

The resulting updates have produced a much more flexible tool, one that's customisable, and colorful. It's also one that supports familiar Windows features that never made it to the old console: now you can use Ctrl-C and Ctrl-V to cut and paste text between the console and the rest of the Windows environment. There's also support for Windows accessibility tools, so you can use Narrator to add text-to-speech capabilities to your console.

windows-consolearchitecture.png

The Windows Console is built on top of a kernel mode driver that handles the connection between the console and any command-line services you're using.

Image: Microsoft

The Windows Console is deeply integrated into the OS, built on top of a kernel mode driver that handles the connection between the console and any command-line services you're using. This approach allows you to have many different console windows open, all handling different operations. The console application itself is written in C for efficiency, and manages the buffers and parsers that take the flow of data to and from command line apps. It's not actually sending text, instead it uses Windows I/O Control messages.

It's important to understand that the Windows Console does not host command-line applications — it's not the tool that launches them. Instead it's a user interface layer to command-line apps that's launched by the underlying app. There's no direct connection between the two: everything is handled by control messages sent between APIs.

SEE: Working in IT: Why we love it, why we hate it (free PDF) (TechRepublic)

The underlying API model in the Windows Console is one of the things that has made it hard for Windows to support UNIX and Linux applications, as they both have different ways of delivering text-mode applications. Supporting Linux text-user interfaces has meant improving support for ANSI/VT sequences. These are used to create complex colored text sequences that offer similar experiences to DOS applications, with tools like curses turning that familiar console display into an interactive environment. Running Linux binaries on Windows lets the OS intercept these streams of commands, translating them to console API calls (and vice versa).

Microsoft is doing a lot to improve the Windows Console: what we have today is a considerable improvement over previous releases, and almost at parity with various UNIX consoles. There are still issues, and the underlying architectural differences between Windows and UNIX will affect what can be supported and when.

Developers and system administrators will always need a command-line tool. An updated and improved Windows Console might not be a tool for all of us, but it's definitely one that a very influential community wants. With improved Linux support for WSL driving much of the Windows command-line development, we can look forward to seeing many more improvements over the next couple of years.

Further reading

How to prevent problems with remote desktop authentication after recent updates to Windows servers

The problem appears to be caused by a May 2018 update and affects connectivity with Windows virtual systems.

How to resolve network problems caused by the Windows 10 April 2018 update

Microsoft's recent Windows 10 update can cause problems with network connectivity. Here's how one systems admin solved them.

Evernote: A cheat sheet

The age of the notepad has ended. In its place are apps like Evernote, which puts your notes in the cloud so you can grab them from anywhere. Here's what you need to know about Evernote.

How to lock down the Settings app in Windows 10

Microsoft's streamlined Settings application lets users modify vital Windows 10 components. Here's how to prevent unauthorized changes to how the OS operates.

10 PowerShell cmdlets you can use instead of CMD commands

CMD has been around for decades, but PowerShell has become a more efficient tool for managing Microsoft products. These PowerShell cmdlets can knock out tasks you used to handle via the command line.

How to manage your organization's Microsoft Store Group Policy

A Microsoft Store Group Policy can be changed to prevent unauthorized installations and block existing native apps from being launched using AppLocker.

About Simon Bisson

Born on the Channel Island of Jersey, Simon moved to the UK to attend the University of Bath where he studied electrical and electronic engineering. Since then a varied career has included being part of the team building the world's first solid state...

Editor's Picks

Free Newsletters, In your Inbox