microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.54k stars 823 forks source link

Cannot Use Windows EXE From Within WSL 2 #5296

Closed gaia closed 4 years ago

gaia commented 4 years ago

image

$ 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
therealkenc commented 4 years ago

$ echo $PATH

There are no win32 paths in your $PATH so interop isn't going to find explorer.exe.

onomatopellan commented 4 years ago

Something is replacing the path. Try this and post the output:

cd ~
grep -i -e 'PATH' .*
gaia commented 4 years ago

image

onomatopellan commented 4 years ago

I don't see anything weird there. Is that the root user?

therealkenc commented 4 years ago

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.

gaia commented 4 years ago

I don't see anything weird there. Is that the root user?

nope. but the root user has the same issue, no win32 in PATH, no explorer.

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

no /etc/wsl.conf . no windows env variable called WSLENV, if that's what you meant?

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

this does it.

Maybe grep -ril 😏.

too many results with -ril

happy to get to the bottom of this.

therealkenc commented 4 years ago

no windows env variable called WSLENV, if that's what you meant?

Yes. If you don't use WSLENV forget I asked.

too many results with -ril

Yeah, wasn't being real serious about that.

What is needed is to figure out what steps happened leading up to you not seeing your Windows paths automatically marshalled into WSL (or being blown away after getting there). I don't have any easy guesses to offer unfortunately.

wizardnet972 commented 4 years ago

same for me with node.exe. node - command not found.

although node is installed in my windows10 computer. I think something is not right with the path variable.

How to set the $PATH to know the paths in windows?

DESKTOP-BVRD:/tmp/docker-desktop-root/mnt/host/c/Users/myuser# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

WSLUser commented 4 years ago

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=onand 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=offand 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.)

andradei commented 4 years ago

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.

licanhua commented 4 years ago

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
therealkenc commented 4 years ago

Was all ready to forward-dupe this one #5779, but it isn't. On Ubuntu (per OP) /etc/profile doesn't unilaterally initialize the $PATH and I guess never has.

image

12gabriel3 commented 4 years ago

I ran into the same issue after upgrading to windows 2004 and WSL2. System32 was in the PATH but I couldn't execute the commands. Running WSL as an administrator solved the issue.

mcandre commented 4 years ago

I had a workaround for WSL1, but the dang /proc/version output changed case and broke my grep expression. Added -i to account for WSL2.

aragon000 commented 3 years ago

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.

It work

JimmyBringus commented 2 years ago

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.

Where is ".profile"?

HeyITGuyFixIt commented 2 years ago

Where is ".profile"?

@JimmyBringus in your home folder. So ~/.profile.