Book Image

Windows Subsystem for Linux 2 (WSL 2) Tips, Tricks, and Techniques

By : Stuart Leeks
Book Image

Windows Subsystem for Linux 2 (WSL 2) Tips, Tricks, and Techniques

By: Stuart Leeks

Overview of this book

Windows Subsystem for Linux (WSL) allows you to run native Linux tools alongside traditional Windows applications. Whether you’re developing applications across multiple operating systems or looking to add more tools to your Windows environment, WSL offers endless possibilities. You’ll start by understanding what WSL is and learn how to install and configure WSL along with different Linux distros. Next, you'll learn techniques that allow you to work across both Windows and Linux environments. You’ll discover how to install and customize the new Windows Terminal. We'll also show you how to work with code in WSL using Visual Studio Code (VS Code). In addition to this, you’ll explore how to work with containers with Docker and Kubernetes, and how to containerize a development environment using VS Code. While Microsoft has announced support for GPU and GUI applications in an upcoming release of WSL, at the time of writing these features are either not available or only in early preview releases. This book focuses on the stable, released features of WSL and giving you a solid understanding of the amazing techniques that you can use with WSL today. By the end of this book, you’ll be able to configure WSL and Windows Terminal to suit your preferences, and productively use Visual Studio Code for developing applications with WSL.
Table of Contents (16 chapters)
1
Section 1: Introduction, Installation, and Configuration
5
Section 2:Windows and Linux – A Winning Combination
11
Section 3: Developing with the Windows Subsystem for Linux

Calling Windows scripts from Linux

If you're used to running PowerShell in Windows, then you will also be used to being able to directly call PowerShell cmdlets and scripts. When you are running PowerShell scripts in WSL, you have two options: install PowerShell for Linux or call PowerShell in Windows to run the script. If you are interested in PowerShell for Linux, the install documentation can be found at https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7. However, since this chapter is focused on calling Windows from WSL, we will look at the latter option.

PowerShell is a Windows application and is in the Windows path, so we can call it using powershell.exe from Linux, as we saw in the last section. To run a command with PowerShell, we can use the -C switch (short for -Command):

$ powershell.exe -C "Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System"
Component Information...