The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

If you can read me, I'm broken!

Views: 9,965     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: April 8, 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:

  1. Retain the working directory as the WSL command prompt except in the scenario explained below.
  2. Have the same permission rights as the bash.exe process.
  3. Run as the active Windows user.
  4. 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 like dir 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.

⇧ List gsettings changes from default vnstat - combine WiFi and Ethernet usage together  ⇩