"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
Are you with ARM device?
No, it's a x64
Hello, I see no answers. If other info are required in order to identify the reason of this behavior, just name them and I'll provide as soon as possible.
@gAllegr I have the same problem. Did you figure out a solution?
@gAllegr I have the same problem. Did you figure out a solution?
Unfortunately no
I am facing the same problem. Wondering why was this issue closed. The issue linked to above was also not resolved.
I am facing the same problem. at startup, all good
$ /mnt/c/WINDOWS/system32/cmd.exe
Microsoft Windows [Version 10.0.19042.844]
(c) 2020 Microsoft Corporation. All rights reserved.
after run docker login
$ /mnt/c/WINDOWS/system32/cmd.exe
/mnt/c/WINDOWS/system32/cmd.exe: Invalid argument
Facing the same issue. WSL used to work fine, not sure how long ago after a round of windows update, all windows commands executed in WSL started to throw "Invalid argument" error.

I am encountering the identical problem

Windows version: 10.0.21337 Build 21337 WSL 2 Ubuntu 20.04.2 LTS
This appears to be the same issue as #4260
I find a work arround for now using bash/ash shell, by mounting the folder as disk drive see https://github.com/microsoft/WSL/issues/5718#issuecomment-671035212 to mount the network location as drive (on insider should be wsl.local)
You can create file on ~/.local/bin for cmd
for cmd command, for ash change first line to #!/bin/ash
#!/bin/bash
cwd=$(pwd)
if ! echo "$cwd" | grep -q "/mnt/"; then
cd /mnt/c/
param="cd /d Z:$cwd"
if [ ! -z "$@" ]
then
param=$param" && $@"
fi
cmd.exe /K "$param"
else
cmd.exe /K "$@"
fi
for powershell you could create psh file, change #!/bin/bash to #!/bin/ash if you using ash shell/alpine
#!/bin/bash
cwd=$(pwd)
if ! echo "$cwd" | grep -q "/mnt/"; then
cd /mnt/c/
param="cd Z:$cwd; powershell "
if [ ! -z "$@" ]
then
param=$param" -c $@"
fi
powershell.exe -c "$param"
else
powershell.exe -c "$@"
fi
for git on windows/for windows
#!/bin/ash
cwd=$(pwd)
if ! echo "$cwd" | grep -q "/mnt/"; then
cd /mnt/c/
param="cd /d Z:$cwd"
param=$param" && git $@ & exit"
cmd.exe /K "$param"
else
cmd.exe /K "git $@ & exit"
fi
then make the executable
chmod +x /home/<your username>/.local/bin/*
Then after that on ~/.bashrc you could add path
PATH=$PATH":/home/<your username>/.local/bin"
If you want to test the change run source ~/.bashrc
if your're on ash/alpine write to ~/.profile
I hope this workarround help a while, I test it on Fedora WSL 34 and Alpine WSL.
Hope the wsl team could fix this problem. Hopefully, because this reproducable even on insider with new ISO which make me insane :'(
the result should be like this
BEN-TP-X220:~$ cd .ssh
BEN-TP-X220:.ssh$ pwd
/home/benli/.ssh
BEN-TP-X220:.ssh$ cmd
Z:\home\benli\.ssh>exit
BEN-TP-X220:.ssh$ cmd echo abc
ash: abc: unknown operand
Z:\home\benli\.ssh>exit
BEN-TP-X220:.ssh$ cmd 'echo abc'
abc
Z:\home\benli\.ssh>exit
BEN-TP-X220:.ssh$ psh "echo abc"
abc
BEN-TP-X220:.ssh$ psh
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
PS Z:\home\benli\.ssh> exit
BEN-TP-X220:.ssh$ git status
fatal: not a git repository (or any of the parent directories): .git
BEN-TP-X220:.ssh$ ls -al ~/.local/bin
total 20
drwxr-sr-x 2 benli benli 4096 Jul 19 18:57 .
drwx--S--- 4 benli benli 4096 Jul 19 17:47 ..
-rwxr-xr-x 1 benli benli 225 Jul 19 18:53 cmd
-rwxr-xr-x 1 benli benli 247 Jul 19 19:04 git
-rwxr-xr-x 1 benli benli 249 Jul 19 19:07 psh
BEN-TP-X220:.ssh$
I can did this because strangely it works on /mnt/c/ directory, at least the windows exe work on windows partition.
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!
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.
I have the same issue, but I have verified that it only happens when my pwd is a network drive.
Example:
$ echo test | clip.exe # this works OK
$ sudo mount -t drfvs '\\path\to\network\drive' /mnt/example
$ cd /mnt/example
$ echo test | clip
/mnt/c/WINDOWS/system32/clip.exe: Invalid argument
As a workaround, make a shell script called clip and place it somewhere in your path. This seems to work.
#!/usr/bin/bash
curdir=$PWD
cd /
cat | clip.exe
cd $curdir
Now you can just do
$ echo test | clip
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 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:
--cd <Directory>
Sets the specified directory as the current working directory.
If ~ is used the Linux user's home path will be used. If the path begins
with a / character, it will be interpreted as an absolute Linux path.
Otherwise, the value must be an absolute Windows path.
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.
Interestingly WSL is in this state almost everytime I start my computer.
If I do a wsl --shutdown then the problem goes away wether or not I use --cd or not.
Add VSCode to the path this solved to me.
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 in cmd or ps shell:
wsl --shutdown
wsl
This has something to do with .git, whenever I do a code . from a directory under Git I get the Invalid Argument, however when I do it from any other folder it works just fine!
Edit - I believe the cause of this was CRLF line endings in the Git metadata files, What I did was deleted my GIT repo and cloned it again into my Linux filesystem using the native Linux client of Git so it creates the proper LF line endings, No more issues starting VS Code.