Ability to list distributions programmatically
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 33.7k
- Forks
- 1.8k
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 116
Description
Is your feature request related to a problem? Please describe.
My use case is to list installed WSL distributions programmatically: the distribution names, the default distribution name and WSL version (1 or 2) are needed.
The command wsl.exe --list --verbose displays all the necessary information, but the output is inconvenient to parse:

The command wsl.exe --list prints the distribution names and the default distribution name. Unfortunately, it looks like the output is still more human-readable. Since human-readable output tends to change over time, I'm not entirely sure if it can be reliably parsed:

The command wsl.exe --list --quiet the prints distribution names only, however the output looks reliable for parsing:

There is also WSL API, but it lacks capability to enumerate installed distributions (#4644) and it doesn't allow to get the default distribution name.
There may be another way to get the needed information. I'd appreciate if you point me in the right direction. If there is no other way, it'd be great to have one.
A few questions regarding wsl.exe --list --quiet:
- What character encoding does it use to produce output? Seems it's
UTF_16LE, is it true? Can the output encoding be changed in future? - Is it guaranteed that every line in the output is a WSL distribution name? Should a parser validate distribution names by using a regexp like
/[a-z0-9.-]+/i?
Describe the solution you'd like
The preferred solution would be WSL API that would allow to get the needed information: list of installed distributions, the default distribution name, WSL version for each distribution (1 or 2).
Another solution that would work is to produce machine readable output by wsl.exe --list. E.g. pass --json option to get JSON output.
Describe alternatives you've considered
Currently, it looks like wsl.exe --list --quiet produces output reliable for parsing. Unfortunately, the output contains the distribution names only, and the rest of the information is missing.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the wsl.exe --list, --list --verbose, and --list --quiet entry points, then read the linked WSL API documentation. Done means providing a supported way to enumerate installed distributions, identify the default distribution, and obtain each distribution's WSL version, either through the API or machine-readable CLI output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- api, cli, operating-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100