Windows命令行中是否有“哪個”的等價物?由于有時我有路徑問題,其中一個自己的cmd腳本被另一個程序隱藏(隱藏在路徑的前面),所以我希望能夠在Windows命令行中找到一個程序的完整路徑,只要給出它的名稱。是否與UNIX命令“哪個”等效?在UNIX上,which command打印給定命令的完整路徑,以便輕松查找和修復這些隱藏問題。
3 回答

開心每一天1111
TA貢獻1836條經驗 獲得超13個贊
where
c:\> for %i in (cmd.exe) do @echo. %~$PATH:i C:\WINDOWS\system32\cmd.exe c:\> for %i in (python.exe) do @echo. %~$PATH:i C:\Python25\python.exe
PATH
@echo off setlocal enableextensions enabledelayedexpansion :: Needs an argument. if "x%1"=="x" ( echo Usage: which ^<progName^> goto :end ) :: First try the unadorned filenmame. set fullspec= call :find_it %1 :: Then try all adorned filenames in order. set mypathext=!pathext! :loop1 :: Stop if found or out of extensions. if "x!mypathext!"=="x" goto :loop1end :: Get the next extension and try it. for /f "delims=;" %%j in ("!mypathext!") do set myext=%%j call :find_it %1!myext! :: Remove the extension (not overly efficient but it works). :loop2 if not "x!myext!"=="x" ( set myext=!myext:~1! set mypathext=!mypathext:~1! goto :loop2 ) if not "x!mypathext!"=="x" set mypathext=!mypathext:~1! goto :loop1 :loop1end :end endlocal goto :eof :: Function to find and print a file in the path. :find_it for %%i in (%1) do set fullspec=%%~$PATH:i if not "x!fullspec!"=="x" @echo. !fullspec! goto :eof
- 3 回答
- 0 關注
- 745 瀏覽
添加回答
舉報
0/150
提交
取消