Views:
10,354
Votes: 6
✅ Solution
Tags:
command-line
java
jdk
symbolic-link
windows-subsystem-for-linux
Link:
🔍 See Original Answer on Ask Ubuntu ⧉ 🔗
URL:
https://askubuntu.com/q/1170907
Title:
Can I create a symlink to a Windows executable in the Windows Subsystem for Linux (WSL) PATH?
ID:
/2019/09/04/Can-I-create-a-symlink-to-a-Windows-executable-in-the-Windows-Subsystem-for-Linux-_WSL_-PATH_
Created:
September 4, 2019
Edited: September 4, 2019
Upload:
September 15, 2024
Layout: post
TOC:
false
Navigation: false
Copy to clipboard: false
You need to prefix the executable with its path. Alternatively you can modify the Linux PATH
environment variable and append the Windows path (prefixed with /mnt/c/
).
From: Windows Subsystem for Linux interoperability with Windows
Invoking Windows binaries from WSL
The Windows Subsystem for Linux can invoke Windows binaries directly
from the WSL command line. Applications run this way have the
following properties:
- Retain the working directory as the WSL command prompt except in the scenario explained below.
- Have the same permission rights as the bash.exe process.
- Run as the active Windows user.
- Appear in the Windows Task Manager as if directly executed from the CMD prompt.
Example:
$ /mnt/c/Windows/System32/notepad.exe
In WSL, these executables are handled similar to native Linux
executables. This means adding directories to the Linux path and
piping between commands works as expected. Examples:$ export PATH=$PATH:/mnt/c/Windows/System32 $ notepad.exe $ ipconfig.exe | grep IPv4 | cut -d: -f2 $ ls -la | findstr.exe foo.txt $ cmd.exe /c dir
The Windows binary must include the file extension, match the file
case, and be executable. Non-executables including batch scripts and
command likedir
can be run with/mnt/c/Windows/System32/cmd.exe /C
command.Examples:
$ /mnt/c/Windows/System32/cmd.exe /C dir $ /mnt/c/Windows/System32/PING.EXE www.microsoft.com
Parameters are passed to the Windows binary unmodified.
Even in Linux symbolic links contain the path. Take for example this command:
$ ls -la /bin | grep ^l
(...SNIP...)
lrwxrwxrwx 1 root root 20 Jun 27 09:49 systemd -> /lib/systemd
systemd
is linked to /lib/systemd/systemd
. So your symbolic link of:
sudo ln -s -t java.exe java
I imagine (because I’m not a link expert) would need to look something like:
sudo ln -s -t /mnt/c/Windows/Path/To/java.exe java
## ```
## Use `alias` instead of symbolic link
Rather than a symbolic link I would create an alias in my `~/.bashrc` file thusly:
alias java=’/mnt/c/WindowsPathTo/java.exe’ ```
Then whenever you type java
the mumbo-jumbo is typed on your behalf. Any parameters passed are honoured.