WSL: "Invalid argument" when executing Windows commands on Ubuntu 20.04
Environment
Windows build number: 10.0.19041.572
Your Distribution version: Ubuntu 20.044
Whether the issue is on WSL 2 and/or WSL 1: WSL 2
Steps to reproduce
WSL logs:
Expected behavior
When I run code . inside the root path or some subfolder of linux, VS Code on Windows should be opened, just like it happen when I run the command from the mount folder.
Same for the explorer.exe command (and all Windows commands). When I run them from root or a subfolder, the command should be executed.
Actual behavior
The system print me back an error saying Invalid argument
Note: I searched in previous issues for some help on how to solve this, but didn’t found how to
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 50
- Comments: 78 (3 by maintainers)
UPDATE Better solution here: https://github.com/microsoft/WSL/issues/6170#issuecomment-1117689071
I have this issue sometimes. Not yet sure why. It’s because the wsl network drives aren’t mapped correctly. So the path then won’t work and this is why it is an
Invalid argument. The path can simply not be resolved. A fast fix incmdorpsshell:The above release doesn’t appear to have fixed the issue for me.
I’m on WSL Release 2.1.0 (in a windows terminal):
but from inside Ubuntu on WSL from my home directory:
For me, WSL may work for a few hours without this problem, but at some point it appears. Once it starts, every
.exeprogram will show this error. The only “fix” is towsl --shutdownwhich is obviously very inconvenient.Interestingly WSL is in this state almost everytime I start my computer.
If I do a
wsl --shutdownthen the problem goes away wether or not I use--cdor not.I am running Windows 11 Pro and encountered this same issue. It was working fine at first, but suddenly stopped. As a workaround, I found the following command from the docs to work from the Windows cmd prompt (https://code.visualstudio.com/docs/remote/wsl):
code --remote wsl+<distro name> <path in WSL>I am wondering if a recent update changed the way paths are handled. I did not notice the remote server was reinstalled in WSL after issuing the above command.
I have the same kind of Schrödinger bug that comes and disappears randomly.
Right now it’s working, but few days ago here is what I got
and when moving on a Windows directory
The
wsl --shutdownworkaround does fix it temporarily, but it’s a major inconvenience. Both Docker Desktop and VS Code misbehave when wsl is yanked out from under them, so I end up needing to close all my Code windows and shut down Docker before doing it.I’ve not tracked down what causes the “Invalid argument” to start happening - I used to think it was sleeping/hibernating that was the issue, but I’ve observed it happening even without sleep.
It happens at least once a day. This issue and #4698 are both major barriers preventing me from recommending WSL2 to anyone as a daily driver for work.
I encountered this today on: WSL version: 2.1.5.0 Kernel version: 5.15.146.1-2 WSLg version: 1.0.60 MSRDC version: 1.2.5105 Direct3D version: 1.611.1-81528511 DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp Windows version: 10.0.19045.4291
wsl --shutdownfixed it for me, we’ll see if it comes back.@OneBlue or @craigloewen-msft Hello, any news/updates on this issue? Several users have reported this issue going back almost 3 years now, but there have been no fixes, or acknowledgements even.
I am encountering the identical problem
Windows version: 10.0.21337 Build 21337 WSL 2 Ubuntu 20.04.2 LTS
+1, I believe this issue is not resolved.
FWIW, a wsl --uninstall and re-install solved it for the same version. Its possible that the container was created with an older version and hence the problem randomly manifested
I got this bug after I installed 11 over 10. I noticed something interesting but very weird and hard to debug. If I’m in root’s home or / the error happens but if I cd to /mnt/c it goes away (!).
I have the same issue, but I have verified that it only happens when my
pwdis a network drive.Example:
As a workaround, make a shell script called
clipand place it somewhere in your path. This seems to work.Now you can just do
Same issue here running Debian WSL2 - I can invoke commands at first open, but after running a few commands, they end up stating “Invalid Argument”. Also, WSL2 seems to forget where the current working directory is sporatically. I have a rust program calling env::current_dir() at different times in it’s lifecyle, and the command eventually fails (not at it’s first invocation, but when called in a later method). It will then completely fail on any subsequent execution, until I create a new terminal.
UPDATE: I updated Windows 10 Home to Windows 10 Education (which is Windows 10 Enterprise plus some educational cruft). I uninstalled and reinstalled WSL 2 and Ubuntu 20.04 LTS. THE PROBLEM PERSISTS.
ORIGINAL POST:
I wish I were equipped to help. All I can do is to further confirm the problem.
Edition: Windows 10 Home (I know, but it’s supposed to work now; and essentially all university students using Windows are using Windows 10 Home on a personal laptop, so that’s what we have to target here.) Version: 21H1 OS Build: 19043.1151 (right up to date)
One bit of evidence I can offer: Replacing Ubuntu 20.04 LTS with 18.04 doesn’t help.
Some kind of guidance / repair is urgently needed here (at least by me); I was planning on having this working by the time classes start at a University in just a few weeks. Again, deep apologies, but I’m not equipped to resolve the issue on the WSL / Ubuntu side. Any kind of update would be extremely helpful!
I am facing the same problem. at startup, all good
after run docker login
Fixed with https://github.com/microsoft/WSL/releases/tag/2.1.0
I had to implement a workaround to keep our GitHub runners working, so I cannot reproduce this specific problem. However, I created a small repro that may help. Essentially it triggers a race that causes the process creation to fail due to an invalid current directory. Not sure if the root cause is the same (here the current directory being non-existent), but the outcome is the same. I have also seen the problem that the original post is referring to, where I am in the users home directory and the Windows process creation fails consistently (which sounds more like a communication problem with the VM).
I am sending you the logs via e-mail.
If I make the usleep delay sufficiently large, it works:
This might helps someone else here. I just got this issue this morning. Not sure what changed, everything was working fine yesterday. Last night I hibernated. This morning I noticed that WSL started up faster than usual, which surprised me as it usually takes a minute. Then I do my usual
And I get that
Invalid argumenterror. Code is working fine from Windows.Then, I closed WSL session and from Powershell, I did
wsl --shutdownRestarted WSL and now Code is working again!
Had this problem lately when trying to call vscode on WSL2.
Then one day I was looking at my Task Scheduler when I noticed this task:
I didn’t create it. Maybe Docker Desktop did?
Anyway I disabled this task and one reboot later, voilá, problem solved.
I created a simple script and added a symlink to replace the normal
code:It works for me for what I need (just open VSCode loading a folder or file)
I see this pop up seemingly randomly. Doing a
wsl --shutdownand restarting my terminal fixes it for the next hour or two.It’s definitely have something to do with path. Here is an easy reproducible workaround: Starting test (can be any directory, or even without specifying directory):
wt nt wsl --cd /Inside WT:
Note: It’s just necessary to issue a ‘cd’ command. But not necessary to actually change the directory. This is not environment related, as the only difference is “OLDPWD”. Setting it explicitly doesn’t work.
WT version 1.12.3472.0 O/S Ubuntu 18.04 WSL version 2
This appears to be the same issue as #4260
So at least for me, I have found the Invalid argument behavior was caused by the WSL_DISTRO_NAME environment variable in Linux not matching my distro name from “wsl --list”, note this behavior is easily reproducible:
(~)[513]> set |grep WSL WSL_DISTRO_NAME=Ubuntu-22.04
(~)[514]> net.exe The syntax of this command is:
NET [ ACCOUNTS | COMPUTER | CONFIG | CONTINUE | FILE | GROUP | HELP | HELPMSG | LOCALGROUP | PAUSE | SESSION | SHARE | START | STATISTICS | STOP | TIME | USE | USER | VIEW ]
(~)[515]> export WSL_DISTRO_NAME=not_the_right_name
(~)[516]> net.exe /mnt/c/Windows/System32/net.exe: Invalid argument
(~)[517]> export WSL_DISTRO_NAME=Ubuntu-22.04
(~)[518]> net.exe The syntax of this command is:
NET [ ACCOUNTS | COMPUTER | CONFIG | CONTINUE | FILE | GROUP | HELP | HELPMSG | LOCALGROUP | PAUSE | SESSION | SHARE | START | STATISTICS | STOP | TIME | USE | USER | VIEW ]
I’m running into the same issue.
wsl -v WSL version: 1.0.3.0 Kernel version: 5.15.79.1 WSLg version: 1.0.47 MSRDC version: 1.2.3575 Direct3D version: 1.606.4 DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp Windows version: 10.0.19045.2486
$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 22.04.1 LTS Release: 22.04 Codename: jammy
Steps to reproduce
$ pwd /home/fabrice $ cmd.exe /mnt/c/windows/system32/cmd.exe: Invalid argument
$ cmd.exe /mnt/c/windows/system32/cmd.exe: Invalid argument
$ cd /mnt/c $ cmd.exe Microsoft Windows [Version 10.0.19045.2486] © Microsoft Corporation. All rights reserved.
C:>exit $ cd - $ pwd /home/fabrice $ cmd.exe /mnt/c/windows/system32/cmd.exe: Invalid argument
I can reproduce this issue on Windows 10 and Windows 11 using the below shell script. Note that you need to run this script twice if the first time succeeds for some reason:
Output:
My observations:
cdafter running docker. Even a simplecd .fixes it.root@OSHAH:/my-app# serve -s build ERROR: Cannot copy to clipboard: Command failed: /root/.nvm/versions/node/v18.4.0/lib/node_modules/serve/node_modules/clipboardy/fallbacks/windows/clipboard_x86_64.exe --copy /root/.nvm/versions/node/v18.4.0/lib/node_modules/serve/node_modules/clipboardy/fallbacks/windows/clipboard_x86_64.exe: Invalid argument
I tried to copy the chrome.exe from the Windows “Program Files” directory to /var/tmp/, then run it , got the same issue, why: root@DESKTOP-R0EA0CF:/home/gwz/sec# cp /mnt/c/Program\ Files/Google/Chrome/Application/chrome.exe /var/tmp root@DESKTOP-R0EA0CF:/home/gwz/sec# root@DESKTOP-R0EA0CF:/home/gwz/sec# root@DESKTOP-R0EA0CF:/home/gwz/sec# /var/tmp/chrome.exe /var/tmp/chrome.exe: Invalid argument root@DESKTOP-R0EA0CF:/home/gwz/sec# But if I run the /mnt/c/Program\ Files/Google/Chrome/Application/chrome.exe, it’s ok.
I’m faced with the same problem of getting
Invalid Argument. It’s unbelievable that the issue has not been resolved after almost 1.5 years.And then there’s also the issue with not being able to access the network drive under
\\wsl$from Windows File Explorer unless you map it to e.g. Z:\ drive. I don’t know if they’re related but there are many issues opened related to this, too.Add VSCode to the path this solved to me.
I have a new piece of information. Windows Terminal was recently changed to let you specify a linux path as the starting directory. When I open Ubuntu-20.04 with my Linux path in there, I get the Invalid Argument errors. If I leave it the default of
%USERPROFILE%then it works fine. I think under the hood Windows terminal is using the new command line argument:If I try this from Powershell, if I do “wsl --cd /home/username” then it can’t run Windows executables.
But if I launch a wsl without the
--cd, then it works.