The Computer Oracle

wsl' is not recognized as an internal or external command

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Sunrise at the Stream

--

Chapters
00:00 Wsl' Is Not Recognized As An Internal Or External Command
00:48 Answer 1 Score 15
01:19 Answer 2 Score 6
01:50 Accepted Answer Score 3
03:16 Thank you

--

Full question
https://superuser.com/questions/1501478/...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#linux #windows10 #commandline #windowssubsystemforlinux

#avk47



ANSWER 1

Score 15


Common problem when trying to access 64-bit tools from 32-bit processes. wsl.exe is in System32. But if your script happens to run as a 32-bit process, then all accesses to System32 are redirected to SysWOW64. In order to access wsl.exe in the "real" System32 folder, you'll have to use Sysnative instead, like in C:\Windows\Sysnative\wsl.exe.




ANSWER 2

Score 6


This error is covered in the "Troubleshooting installation" section of the WSL installation guide:

The term 'wsl' is not recognized as the name of a cmdlet, function, script file, or operable program.

Ensure that the Windows Subsystem for Linux Optional Component is installed. Additionally, if you are using an ARM64 device and running this command from PowerShell, you will receive this error. Instead run wsl.exe from PowerShell Core, or Command Prompt.




ACCEPTED ANSWER

Score 3


The most common reason why a command which runs an executable program works on the command line, but not in a batch script, is that, in the script, prior to the line containing the problem command, the user has created a variable %path%. It might seem a handy name for a variable that holds, well, a path. The problem is that this variable name is used by Windows to hold a semicolon-separated list of folders which are searched when an executable is called. It is a system variable. If you have redefined it, then all executables (e.g. .exe, .bat, .vbs, etc) that Windows uses, will not be found, and the script will fail with exactly this message, where xxx is the program or file that is expected:

'xxx' is not recognized as an internal or external command, operable program or batch file.

This can be confusing because commands which are internal to the cmd environment (dir, cls, set, copy, move, etc) (list here) still continue to work in this situation.

You can debug a script where this is suspected by inserting the path command immediately before a problem line. The Windows path variable starts with these folders, and may be extended as programs are installed:

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem