microsoft / WSL

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

Spaces in inherited windows PATH messing with env comand #6484

Closed lopugit closed 3 years ago

lopugit commented 3 years ago

Environment

Windows build number: Microsoft Windows [Version 10.0.21296.1010]
Your Distribution version: 20.04
Whether the issue is on WSL 2 and/or WSL 1: Linux version 5.4.72-microsoft-standard-WSL2 (oe-user@oe-host) (gcc version 8.2.0 (GCC)) #1 SMP Wed Oct 28 23:40:43 UTC 2020

Steps to reproduce

When using PM2, a popular process manager for linux, it's installed via npm, when adding a startup config for it, it asks you to copy paste an env command, this command fails due to the Windows PATH modification done to WSL. I have tried disabling Windows PATH injection in wsl.conf but doing so makes vscode/wsl co-op brake.

lopu@win:~/things/git/lopugit/thingtime/dev-thingtime$ pm2 startup
[PM2] Init System found: systemd
[PM2] To setup the Startup Script, copy/paste the following command:
sudo env PATH=$PATH:/home/lopu/.nvm/versions/node/v14.15.4/bin /home/lopu/.nvm/versions/node/v14.15.4/lib/node_modules/pm2/bin/pm2 startup systemd -u lopu --hp /home/lopu       
lopu@win:~/things/git/lopugit/thingtime/dev-thingtime$ sudo env PATH=$PATH:/home/lopu/.nvm/versions/node/v14.15.4/bin /home/lopu/.nvm/versions/node/v14.15.4/lib/node_modules/pm2/bin/pm2 startup systemd -u lopu --hp /home/lopu
[sudo] password for lopu: 
env: ‘Files’: No such file or directory
lopu@win:~/things/git/lopugit/thingtime/dev-thingtime$ echo $PATH
/home/lopu/.nvm/versions/node/v14.15.4/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Python39/Scripts/:/mnt/c/Python39/:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/mnt/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR:/mnt/c/Program Files/nodejs/:/mnt/c/ProgramData/chocolatey/bin:/mnt/c/Users/lopu/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/lopu/AppData/Local/Programs/Microsoft VS Code Insiders/bin:/mnt/c/Users/lopu/AppData/Local/hyper/app-3.0.2/resources/bin:/mnt/c/Users/lopu/AppData/Roaming/npm:/snap/bin
lopu@win:~/things/git/lopugit/thingtime/dev-thingtime$

WSL logs:

Expected behavior

env command should run successfully,

Actual behavior

error's because of spaces in PATH due to windows injection

lopugit commented 3 years ago

changing sudo env PATH=$PATH:/home/lopu/.nvm/versions/node/v14.15.4/bin /home/lopu/.nvm/versions/node/v14.15.4/lib/node_modules/pm2/bin/pm2 startup systemd -u lopu --hp /home/lopu to sudo env PATH="$PATH":/home/lopu/.nvm/versions/node/v14.15.4/bin /home/lopu/.nvm/versions/node/v14.15.4/lib/node_modules/pm2/bin/pm2 startup systemd -u lopu --hp /home/lopu fixed it

lopugit commented 3 years ago

Although now this made me learn that WSL doesn't have systemd working ... WHAT?!

therealkenc commented 3 years ago

Thanks; beat me while I was typing. You might ask the PM2 guys to add the quotes around $PATH in the prompt. Having spaces is uncommon on Linux but common on WSL. Landing zone for systemd is #994.

lopugit commented 3 years ago

Thanks; beat me while I was typing. You might ask the PM2 guys to add the quotes around $PATH in the prompt. Having spaces is uncommon on Linux but common on WSL. Landing zone for systemd is #994.

haha I had been reading into it a fair bit and realised it was probably that.

Have you read this article? https://wsl.dev/wsl2-microk8s/

I've gotten systemd working via it, although he puts NOPASSWD: ALL in his %sudo group /etc/sudoers file which I would never do so it just means you need to enter sudo password everytime you start a session, which is a bit annoying but safer than having NOPASSWD...?!?!?

found here: https://github.com/microsoft/WSL/issues/4202#issuecomment-692240678

0x1100010010 commented 3 years ago

Just add quotes around Path variable, sudo env "PATH=$PATH":/your_path Took me around 4 hrs to figure out.

BrianRonin commented 2 years ago

Basta adicionar aspas em torno da variável Path, sudo env "PATH=$PATH":/your_path Levei cerca de 4 horas para descobrir.

meu deus é cada coisa, eu só me surpreendo com a programação e tu é br que ironia nem percebi porque ta sempre traduzido, vlw funciono aqui tamo junto

sachinmyneni commented 4 months ago

SET WSLENV=Path/lpu and then start wsl

This translates the paths between linux in WSL and windows.

Source: https://devblogs.microsoft.com/commandline/share-environment-vars-between-wsl-and-windows/