WSL: Cannot Use Windows EXE From Within WSL 2

image

  • What’s wrong / what should be happening instead: explorer.exe should be in path and launch
$ echo $PATH
/home/user/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 4
  • Comments: 17 (2 by maintainers)

Most upvoted comments

For Debian, /etc/profile contributed to this problem.

Here is the path definition in /etc/profile

if [ "`id -u`" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
  PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
fi

You can delete above lines, then wsl --shutdown to restart Debian.

If you would like to keep these lines, you can also append “:$PATH” to each path like below, then wsl --shutdown

if [ "`id -u`" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH"
else
  PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:$PATH"
fi

For it was my .zshenv file that was setting PATH like this:

export PATH="some/paths/here"

instead of

export PATH="some/paths/here:$PATH" (Notice the appended :$PATH at the end)

I didn’t know $PATH already had content when WLS2 first started, and that it had precisely the Windows PATHs. So my script was overriding that instead of appending to it.

Hopefully this will help others.

Resetting the baseline, there is no appendWindowsPath=false in wsl.conf, right? Also do you happen to be using WSLENV?

You can push through this doing a export PATH=$PATH:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32 in .profile.

But it would be nice to know what happened here for the collective knowledge-base. No guesses from me. The grep was a good stab, thanks onomatopellan. Maybe grep -ril 😏. Actually it would be somewhat weird for something to cleanly sever the Windows paths (and only the Windows paths). Anything possible I guess.

So I had the paths stripped even with the append option enabled using a custom imported distro automatically set up for WSL2 (though I saw this before on WSL1 before upgrade using Pengwin, FedoraRemix, Ubuntu, etc. from Store). I had also turned case=on and as well as having fstab turned on in /etc/wsl.conf. After manually setting the custom distro to version 2 again (even though in wsl --list --verbose, it shows version 2) and also switching case=off and turning fstab off) then doing a wsl --shutdown, interop worked again (you can immediately notice it because it automatically goes to the windows home instead of linux home when interop is working properly.)