1

Possible Duplicate:
Windows equivalent of whereis?

I'm used to saying "which foo" on Unix systems to see what's going to run.

Today I'm having trouble with a program on Windows, and I think it may be the wrong command that's running. How do I determine, from cmd.exe, what program it's actually going to run when I type "foo"?

Ken
  • 2,909
  • 7
  • 25
  • 28
  • 1
    http://superuser.com/questions/21067/windows-equivalent-of-whereis/39260#39260 – akira Jul 16 '10 at 19:19
  • akira: Great find! (I was having trouble getting SU to believe that I wanted to find the word "which".) Can I bless a comment into an answer? :-) – Ken Jul 16 '10 at 19:56

4 Answers4

0

I would suggest, using your "foo" example, typing

foo /?

That should do similar on windows as adding --help does in linux. Not always, mind you, but it should let you know exactly what's going on, as well as some command syntax.

Aeo
  • 2,267
  • 1
  • 16
  • 17
  • But running foo /? doesn't show which directory it is running from, only how to run it, which is not what the OP is asking. – steve.lippert Jul 16 '10 at 19:04
  • @steve.lippert .. true, but getting the usage back often indicates *something* about the program itself - though maybe not enough in all cases – warren Jul 16 '10 at 19:07
  • 1
    Unfortunately, in this case it's a command that has no visible output, or gives a generic error message. From `/?` (and any other flags I can think up) I can't tell exactly which one it's running. – Ken Jul 16 '10 at 19:08
0

I don't know of a 'which' for Windows, but from the command line you can run path to see where it is looking for the files. I believe it searches the path in order and will run the first executable it finds.

Remember that CMD.EXE will also search the local directory for a program to run and I believe this takes precedence.

steve.lippert
  • 2,130
  • 13
  • 14
  • 1
    I thought I've heard that `cmd.exe` has some special cases that aren't in `%PATH%`, which is why I'm asking. Plus I don't love the idea of hunting through all of the paths myself. :-) – Ken Jul 16 '10 at 19:09
0

To expand on steve's answer, from %SYSTEM_ROOT% you can run an attrib search to see where 'foo' lives, then compare to the %PATH% to see which would execute first:

attrib /s foo.exe
...
echo %PATH%
warren
  • 9,920
  • 23
  • 86
  • 147
  • Good to know! But the variable is %systemroot%. cd %systemroot%, attrib /s ping.exe – steve.lippert Jul 16 '10 at 19:20
  • -1: `attrib /s foo.exe` just searches the current directory and all subdirectories for foo.exe. (You could do the same thing with `dir /a-d /s /b foo.exe` or Win+F.) On my computer, %SYSTEMROOT% is C:\WINDOWS, so you're really just searching in that directory and below. You could `cd \ ` first, or use Win+F to search for foo.exe, but those preform really long searches, when you really just need to search the path. – Bavi_H Jul 17 '10 at 01:33
0

The which that comes with Cygwin (http://cygwin.org) will run from cmd.exe and probably do what you want otherwise. Be aware that if you're looking for a .bat, you need to explicitly add the .bat, e.g., "which gorp.bat" will find gorp.bat, but "which gorp" will not.

  • Nice idea, but unfortunately this is a server which doesn't have Cygwin, and I'm not sure they want me installing Cygwin there. – Ken Jul 16 '10 at 19:55