Is there an equivalent of 'which' on the Windows command line?

后端 未结 26 2083
悲哀的现实
悲哀的现实 2020-11-22 00:40

As I sometimes have path problems, where one of my own cmd scripts is hidden (shadowed) by another program (earlier on the path), I would like to be able to find the full pa

相关标签:
26条回答
  • 2020-11-22 01:06

    Just have to post this Windows' one liner batch file:

    C:>type wh.cmd
    @for %%f in (%*) do for %%e in (%PATHEXT% .dll .lnk) do for %%b in (%%f%%e) do for %%d in (%PATH%) do if exist %%d\%%b echo %%d\%%b
    

    A test:

    C:>wh ssh
    C:\cygwin64\bin\ssh.EXE
    C:\Windows\System32\OpenSSH\\ssh.EXE
    

    Not quite a one-liner if you wrap the code in setlocal enableextensions and endlocal.

    0 讨论(0)
  • 2020-11-22 01:07

    For you Windows XP users (who have no where command built-in), I have written a "where like" command as a rubygem called whichr.

    To install it, install Ruby.

    Then

    gem install whichr
    

    Run it like:

    C:> whichr cmd_here

    0 讨论(0)
提交回复
热议问题