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? [closed]

此生再无相见时 提交于 2019-12-08 19:17:57

问题


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

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?


回答1:


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" 

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.

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.

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'.



来源:https://stackoverflow.com/questions/23455637/in-windows-cmd-how-do-i-run-an-executable-in-the-current-directory-instead-of

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!