So, recently I downloaded an Ubuntu installation of Linux for Windows since I wanted to learn how to use a bash shell. I've been enjoying it so far, but was wondering if there was a way to do the above? Say I have iTunes installed on my computer, and I want to open it from my Linux terminal. Is that possible? I've tried going to the desktop folder in the terminal and opening the .lnk files, but it just throws an "cannot execute binary file: Exec format error" at me. Anybody know if it's possible?
-
Linux cannot run Windows executables without WINE. You will have to investigate if WINE supports WSL, if it's supported, it will require WSL2. – Ramhound Mar 15 '21 at 21:22
-
1This depends on the WSL version (at least). I am not running WSL2 so I can't speak for that. @Ramhound is not correct (at least for WSL1.. probably WSL2 also) .. this is RARE. :) First of all.. you can not execute .lnk files. These are linked to the windows explorer (from which you have none).. try typing `notepad.exe` (with extension) and see what happens. WSL to launch windows applications requires the windows app is in the path and that you also use the extension (aka .com or .exe). Try it and let me know how it goes. – Señor CMasMas Mar 15 '21 at 21:53
-
1@Ramhound.. they are married like you don't realize. For instance, I alias start=`explorer.exe` and I can fire up the windows explorer in the current directory from WSL bash using `start .` – Señor CMasMas Mar 15 '21 at 21:57
-
Ummm, “star=Explorer.exe” would start file Explorer in Windows not within WSL. – Ramhound Mar 15 '21 at 23:15
2 Answers
Yes, WSL supports launching Windows application executables (such as iTunes) from within the shell. However, as was mentioned in the comments, lnk files are not supported, since they aren't executables. They are links to executables.
WSL also is nice enough to (by default) append your Windows path to your Linux path. So for applications that are in the path (e.g. notepad.exe), you can just launch them directly with the appname.exe format.
For apps that aren't in the path (e.g. itunes.exe), you'll need to determine the location of the actual .exe (executable), and launch it with the full path. This is really the same as for any Linux executable under Linux, or any Windows executable under Windows PowerShell or CMD.
To find the full path to iTunes, just right click on the lnk file in Explorer and choose "Properties". The "Target" field will have something like C:\Program Files\iTunes\iTunes.exe.
As mentioned previously, if you were trying to launch this in Windows PowerShell or the CMD interpreter (the Windows "equivalents" of bash under Linux), you would still need the full path, so you would run:
C:\Program Files\iTunes\iTunes.exe
To launch that particular path in bash in WSL, you would use:
/mnt/c/Program\ Files/iTunes/iTunes.exe
If you need help converting the Windows path to the Linux path, there's a command for that:
wslpath 'C:\Program Files\iTunes\iTunes.exe'
For detailed information on Windows/WSL interoperability, see this doc.
- 17,574
- 4
- 44
- 81
WSL can launch Windows binaries natively via some interop and the use of binfmt_misc
LNK OTOH isn't an executable file but a kind of file that stores metadata for Windows Shell to link to any kind of files, not only executables. Since it's a normal file you need to open it with some applications. In cmd the way to open any files with the default associated program is to use start. So in older WSL you can do like this
cmd.exe /c start ~/Desktop/iTunes.lnk
Obviously %Windir%\System32 must be in your path (which is done by default) or you'll have to fix your WSL environment. The equivalent in PowerShell is Start-Process or Invoke-Item
powershell.exe -Command Start-Process ~/Desktop/iTunes.lnk
powershell.exe -Command Invoke-Item ~/Desktop/iTunes.lnk
For most kinds of files you can also use explorer.exe directly
explorer.exe ~/Desktop/iTunes.lnk
However in WSL2 you have a new command to do that
wslview ~/Desktop/iTunes.lnk
Some other solutions begin wsl-open and eopen
See
As an example, either of the below commands will open the current directory in Explorer
explorer.exe .
wslview .
powershell.exe -Command Start-Process .
powershell.exe -C Invoke-Item .
cmd /c start .
or to open some pdf files
explorer.exe my.pdf
wslview my.pdf
powershell.exe -Command Start-Process my.pdf
powershell.exe -C Invoke-Item my.pdf
cmd /c start my.pdf
- 26,555
- 15
- 113
- 235
-
Really great point - I hadn't considered the use of "helpers" to proxy the `lnk`. – NotTheDr01ds Mar 16 '21 at 06:00