Skip to content

Determine path of cmd.exe programatically from WSL #5743

@oliversalzburg

Description

@oliversalzburg

Is your feature request related to a problem? Please describe.
Modules like https://www.npmjs.com/package/open are used to, for example, open a URL in a browser. This module has built-in detection for if it is running inside WSL. In which case it will utilize cmd.exe to invoke a browser on the Window side.

This mechanism only works when cmd.exe is available through the $PATH environment variable. This is the default behavior in WSL.

When disabling the attachment of Windows elements to the $PATH environment variable, this entire process no longer works. Disabling the $PATH attachment can be desireable in certain configurations, where you want to ensure that no Windows binaries creep into your environment unintenionally.

Describe the solution you'd like
My idea was some /proc endpoint that would return information about the Windows environment. An equivalent of %SystemDrive% and %SystemRoot% would probably be sufficient.

Describe alternatives you've considered
Reading the base mount point from /etc/wsl.conf, if it exists, then iterating over /<mount_point>/[a-z] and searching for a Windows installation.

This is not feasible. Multiple Windows installations could exist. I'm not sure if exotic configurations are possible where the Windows directory is not named Windows.

A search feels unclean. This information should be accessible through a clear API.

Additional context
sindresorhus/open#186

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions