Windows CMD:如何创建可执行文件的符号链接? [英] Windows CMD: How to create symbolic link to executable file?
问题描述
我的目标是向我的 PATH 添加一些可执行文件(例如,chrome),以便我可以调用
My goal is to add a few executables to my PATH (for example, chrome), so that I can call
> chrome
从命令提示符,它将启动 Chrome.
from the command prompt and it will launch Chrome.
我知道我可以将 Chrome 的包含目录添加到我的路径中 (set PATH=%PATH%<chrome_path_here>;
),但是由于我想添加一些可执行文件,我会而是创建一个新的 bin 目录,其中包含指向实际可执行文件的符号链接,然后将该目录添加到我的 PATH 中.
I know I could add Chrome's containing directory to my path (set PATH=%PATH%<chrome_path_here>;
), but since I have a few executables I want to add, I'd rather make a new bin directory that contains symbolic links to the actual executables and just add that single directory to my PATH.
Chrome 可执行文件位于
The Chrome executable is located at
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
所以我尝试了
> mklink chrome.exe "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
这成功地为文件创建了一个符号链接(在输出中是这样说的,并且在使用 > dir
检查时).当我运行 > 时,我知道我的 PATH 设置正确,b/cchrome
在哪里找到我的新符号链接.
That successfully creates a symbolic link for the files (says so in output, and upon examining with > dir
). I know my PATH is set up correctly, b/c when I run > where chrome
it finds my new symbolic link.
但是,当我尝试使用新链接执行 chrome 时,没有任何反应.应该会出现一个新的空窗口,但没有任何反应.命令提示符或任何内容中没有错误消息.
However, when I try to execute chrome with my new link, nothing happens. A new empty window should appear, but nothing happens. No error message in the command prompt or anything.
我做错了什么?我误解了 Windows 中的符号链接吗?这是我一直在 Linux 中使用的方法,但我是 Windows Cmd 的新手.
What am I doing wrong? Am I misunderstanding symlinks in Windows? This is the approach I use in Linux all the time, but I'm new to Windows Cmd.
谢谢!
推荐答案
大多数程序不会从安装位置以外的位置运行 - 这正是您尝试从符号链接运行时发生的情况.
Most programs will not run from places other than they install location - which is exactly what happens when you try to run it from symlink.
在该文件夹中创建具有匹配名称的 CMD/BAT 文件会容易得多,这些文件将从您想要的位置启动程序:
It would be much easier to create CMD/BAT files in that folder with matching names which will launch programs from locations you want:
REM chrome.cmd
start /b cmd /c "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" %*
这篇关于Windows CMD:如何创建可执行文件的符号链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!