Is there an equivalent of 'which' on the W

2018-12-31 03:33发布

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 path to a program on the Windows command line, given just its name.

Is there an equivalent to the UNIX command 'which'?

On UNIX, which command prints the full path of the given command to easily find and repair these shadowing problems.

22条回答
若你有天会懂
2楼-- · 2018-12-31 03:58

I have created tool similar to Ned Batchelder:

Searching .dll and .exe files in PATH

While my tool is primarly for searching of various dll versions it shows more info (date, size, version) but it do not use PATHEXT (I hope to update my tool soon).

查看更多
明月照影归
3楼-- · 2018-12-31 03:58

None of the Win32 ports of Unix which that I could find on the Internet are satistactory, because they all have one or more of these shortcomings:

  • No support for Windows PATHEXT variable. (Which defines the list of extensions implicitely added to each command before scanning the path, and in which order.) (I use a lot of tcl scripts, and no publicly available which tool could find them.)
  • No support for cmd.exe code pages, which makes them display paths with non-ascii characters incorrectly. (I'm very sensitive to that, with the ç in my first name :-))
  • No support for the distinct search rules in cmd.exe and the PowerShell command line. (No publicly available tool will find .ps1 scripts in a PowerShell window, but not in a cmd window!)

So I eventually wrote my own which, that suports all the above correctly.

Available there: http://jf.larvoire.free.fr/progs/which.exe

查看更多
素衣白纱
4楼-- · 2018-12-31 04:01

I have used the which module from npm for quite a while, and it works very well: https://www.npmjs.com/package/which It is a great multi platform alternative.

Now I switched to the which that comes with Git. Just add to your path the /usr/bin path from Git, which is usually at C:\Program Files\Git\usr\bin\which.exe. The which binary will be at C:\Program Files\Git\usr\bin\which.exe. It is faster and also works as expected.

查看更多
一个人的天荒地老
5楼-- · 2018-12-31 04:02

You can first install Git from Downloading Git, and then open Git Bash and type:

which app-name
查看更多
骚的不知所云
6楼-- · 2018-12-31 04:02

TCC and TCC/LE from JPSoft are CMD.EXE replacements that add significant functionality. Relevant to the OP's question, which is a builtin command for TCC family command processors.

查看更多
无色无味的生活
7楼-- · 2018-12-31 04:03

Not in stock Windows but it is provided by Services for Unix and there are several simple batch scripts floating around that accomplish the same thing such this this one.

查看更多
登录 后发表回答