Windows – How to start an application via a Windows symlink

command linesymbolic-linkwindows

As a developer, I install and run many applications. To access these from the command-line, the usual mechanism to add the applications to the PATH environment variable. That's ok, but leads to a messy, large, impenetrable PATH.

I want to tidy this up by having a single directory, e.g. c:\dev that contains symlinks to all the applications. I can create the symlinks fine with mklink, e.g. mklink eclipse.exe c:\dev\eclipse\eclipse.exe.

For the Eclipse example, when I try the new symlink, I get an error about a companion library. For other apps (e.g. Notepad++) I get a different error.

HOWEVER, when I type the same path directly into the command line, e.g. c:\dev\eclipse\eclipse.exe everything works.

So, a symlink eclipse.exe => c:\dev\eclipse.exe is different to plain c:\dev\eclipse.exe. I was hoping (sigh) and assuming (doh!) that the symlink would work the same as directly typing the full path.

IOW, why is symlink => c:\dev\eclipse.exe not equivalent to typing c:\dev\eclipse.exe?

Is there any way around this? I know I can write little batch files, but I was hoping to avoid that (symlinks seem cleaner).

Is this a Windows idiosyncrasy or is Linux the same?

Best Answer

Let me illustrate the problem with an example. I created a simple one-line batch file Test.bat in C:\Program Files with the following contents:

@echo Batch dir = "%~dp0"

Now from D:\ if I invoke the batch file with C:\Program Files\Test, it says:

Batch dir = "C:\Program Files\"

If I modify the PATH using set path=%path%;C:\Program Files and invoke the batch file with a simple Test, it says:

Batch dir = "C:\Program Files\"

Finally if I create a symlink using mklink Test.bat "C:\Program Files\Test.bat" and invoke it with a simple Test, it says:

Batch dir = "D:\"

As you can see the current working directory is different in this case. No wonder your apps are complaining about files they expect in the executable's directory being missing.

If you don't want to add lots of directories to the PATH just add one that contains batch files for each of your apps.