2

I have a folder of .lnk shortcuts to CLI apps in different folders. The shortcut folder is added to PATH, and my PATHEXT contains the ".lnk" extension. As a result, I can just type ffplay in my shell, and Windows automatically finds the D:/shortcuts/ffplay.lnk file and runs the ffplay.exe executable it points to.

When I run ffplay from cmd, it works as expected, outputs usage help to my terminal and exits. When I do the same from Powershell (it does not matter if it is the old powershell.exe or new pwsh.exe), there is no stdout output, and a new conhost window with the output appears instead.

Is it possible to make the linked commands behave as normal console program executables do?

How to reproduce:

  1. Create a .lnk shortcut to a native command, for example to C:/Windows/System32/PING.EXE, with a different name, so you can run it (so, maybe D:/shortcuts/lnkping.lnk).

  2. Open cmd.exe, cd to shortcut directory, run .\lnkping.lnk 1.1.1.1, output is inline as normal.

    ex. CMD Output

    CMD Link Output - Windows 10 - Screenshot

  3. Open powershell.exe, cd to shortcut directory, run .\lnkping 1.1.1.1 - invocation immediately returns, new conhost window is open and output is displayed there.

    PowerShell CMD/Link Output - Windows 10 - Screenshot

1 Answer 1

-1

Is it possible to make the linked commands behave as normal console program executables do?

The solution to this issue may be not to use .lnk files, but to use .bat files instead e.g.:

ex. lnkping.bat

@Echo Off
C:\Windows\System32\ping.exe %*

%* allows the .bat file to accept any number of additional parameters, which are then passed to the specified executable as if they were typed directly at the command line. And much like .lnk files, under normal circumstances the .bat extension does not need to be included when the "script" is invoked (so e.g. .\lnkping 1.1.1.1 should work without issue).

2
  • 1
    Surprisingly, using .cmd/.bat is about 70ms faster than .lnk files, I expected the opposite. Shortcuts are nice, as they follow their target when it's moved, but .cmd seem fine for my usecase (before running the command, I cd /d to parent directory, otherwise dependencies are broken). I also tried symlinks, which work well if the program does not have any dependencies in its installation folder.
    – a-n
    Commented Apr 13, 2020 at 16:24
  • Indeed. While .lnk files do have certain advantages, the .bat and symlink options are the ones I have personally found to be most useful. Commented Apr 13, 2020 at 22:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .