在Windows cmd中,如何在当前目录中运行可执行文件(而不是在%PATH%中具有相同名称的可执行文件)而不引用完整路径? [英] In Windows cmd, how do I run an executable in the current directory (instead of one with the same name in %PATH%) without referring to the full path?
问题描述
我正在尝试从目录运行可执行文件foobar
,但是Windows碰巧也有一个名为foobar
的可执行文件(或命令).在UNIX中,我只写
I'm trying to run an executable foobar
from a directory, but Windows also happens to have an executable (or command) named foobar
. In UNIX, I'd just write
./foobar
但是Windows cmd似乎不了解这一点.鉴于我不想将此目录添加到我的%PATH%
中,是否有另一种方式来运行当前目录的foobar
而无需显式键入路径?
but Windows cmd doesn't seem to understand that. Given that I don't want to add this directory to my %PATH%
, is there another way to run the current directory's foobar
without typing the path explicitly?
推荐答案
在搜索路径之前,Windows总是先在当前目录中查找. 如果您尝试从程序运行命令,请尝试首先像下面这样"cd"到目录:
Windows always looks in the current directory first before searching the path. If you are trying to run a command from a program, try "cd"ing to the directory first like so:
copy con run_foobar.bat
cd c:\myfoobardirectory
foobar
"<CTRL> + Z"
一种特殊情况是,如果您尝试执行与cmd.exe内部命令名称匹配的文件,例如"date",在这种情况下,即使您在当前目录中具有本地"date.exe"可执行文件.
A special case is if you're trying to execute a file that matches the name of an internal command of cmd.exe, such as 'date', in this case, the internal 'date' command will be executed even if you have a local 'date.exe' executable file in the current directory.
您可以通过在当前目录中键入全名"date.exe"来强制执行本地程序文件,这将覆盖内部的"date"命令.
You can force the executaion of the local program file by typing the full name 'date.exe' in the current directory, this will override the internal 'date' command.
还请注意,在PowerShell中,该行为与Cmd Shell不同,因此,即使在本地目录中的PowerShell中键入"java"或"java.exe"之类的命令,路径命令也将被执行,即使有一个同名的本地文件.要强制执行本地文件,我们将使用Linux样式"./java"或"./java.exe".
Notice also that in PowerShell, the behavior is different to Cmd shell, so even if you type in PowerShell in the local directory a command like 'java' or 'java.exe', then the path command will be executed even if there is a local file with the same name. To force the execution of the local file, we would use the linux style './java' or './java.exe'.
这篇关于在Windows cmd中,如何在当前目录中运行可执行文件(而不是在%PATH%中具有相同名称的可执行文件)而不引用完整路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!