The Unix which statement is very useful in determening which path is used for program run from the command line, and it would be very helpful to have something similar in windows.

link|improve this question
Post up on stackoverflow.com and maybe somebody would write one for you. :-) I imagine it'd be fairly trivial. – Brian Knoblauch Jun 3 '09 at 19:54
feedback

6 Answers

up vote 8 down vote accepted

Save this to a file named which.cmd:

@for %%e in (%PATHEXT%) do @for %%i in (%1%%e) do @if NOT "%%~$PATH:i"=="" echo %%~$PATH:i
@for %%i in (%1) do @if NOT "%%~$PATH:i"=="" echo %%~$PATH:i

Or download UnxUtils - they have lightweight native ports of the most common tools.

Or if you don't care about lightweightness, install Microsoft Services For Unix. Yes, it has Microsoft Vi.

link|improve this answer
2  
Microsoft Vi: pics.livejournal.com/allah_sulu/pic/0005832c – Josh K Jun 4 '09 at 4:35
Or install cygwin – ring0 Oct 11 '10 at 0:55
feedback

I use whereis written by Joseph M. Newcomer (co-author of Win32 Programming).

link|improve this answer
feedback

Nope, no native equivalent. Can't even get command completion with ^F in a cmd /f:on shell, more's the pity.

You can always install a Windows port of a Unix shell environment to get which, of course.

link|improve this answer
Did you try pressing the Tab key for completion? – grawity Jun 3 '09 at 20:01
No, since that's not a Windows cmd.exe completion character, and it doesn't do anything... – chaos Jun 3 '09 at 20:12
Strange, I always used Tab for tab-completion, it worked even on fresh installs. – grawity Jun 3 '09 at 20:16
...though I'm not sure now what /f does. (My phone doesn't have cmd.exe) – grawity Jun 3 '09 at 20:17
Check cmd /? when you have it on hand. It goes on for a while about how it enables ^F for file completion and ^D for directory completion, and how to tweak it. Wish I knew how to turn out this tab completion. :) – chaos Jun 3 '09 at 20:39
show 1 more comment
feedback

You have this with PowerShell. If you don't have PS you can get it from Microsoft. It's free.

Here is an article from Linux-Magazine which touches on the topic of Unix (bash) commands available in PowerShell.

link|improve this answer
feedback

Windows Server 2003/2008 has "where" built in.

link|improve this answer
...or is it in the Reskit/Support Tools. No, I'm sure it's in CMD.EXE... – Simon Catlin Oct 10 '10 at 20:52
feedback

And if your program is interactive you can always check the Task manager. Select the process you want to explore, and choose "Open file Location" from the popup meny

link|improve this answer
I'm sorry, but this does not answer the question being asked. This only provides the path of a running file. The question is asking to find what executable will get called when a command without a path is executed. – Caleb Apr 20 '11 at 10:55
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.