$ | >

A command to confirm that linux is running on WSL

There are many cases where it's useful to programmatically check whether linux is "regular" linux or WSL linus. E.g., in Python calling `sys.platform` just returns `linux`, not `linux-wsl` or something like this. It'd be helpful if there were a command line argument that could reliably confirm that the platform is WSL.

4 votes
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)

    We’ll send you updates on this idea

    Chris H shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    4 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...
      • Dana Myers commented  ·   ·  Flag as inappropriate

        Perhaps naively, I'd ask what the use case(s) is for this; in other words, what will an application do with the knowledge? Having a single 'flag' like this leads applications to infer perhaps a large set of assumptions - assumptions that may not remain valid under newer builds of WSL. If specific features are involved, then specific flags would be much better.

      • Pavel A commented  ·   ·  Flag as inappropriate

        To check if you are running on WSL:

        1. uname -r | grep "Microsoft" && echo "Welcome to Microsoft Linux"

        2. cat /proc/version_signature | grep "Microsoft" && echo "Welcome to Microsoft Linux"

        3. mount|grep "C:" && "Welcome to Microsoft Linux again"

      • Paul Marquess commented  ·   ·  Flag as inappropriate

        Agree that we need an official way to know that your code is running in WSL.

        I currently do this by testing for the presence of the string "Microsoft" in "/proc/version".

      Feedback and Knowledge Base