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.

  • 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

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.

| improve this answer | |

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

| improve this answer | |

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.

| improve this answer | |
  • Did you try pressing the Tab key for completion? – user1686 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. – user1686 Jun 3 '09 at 20:16
  • ...though I'm not sure now what /f does. (My phone doesn't have cmd.exe) – user1686 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

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.

| improve this answer | |

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

| 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

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

| improve this answer | |
  • 1
    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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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