Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Consider the following PATH

c:\App1\;c:\App2\

App1 directory contains the application Foo.exe
App2 directory contains the application Bar.exe

Now when I'm in a CMD window I can type either Foo.exe or Bar.exe.

Now is there a way to know, when I type Foo.exe, that it resolves to C:\App1\Foo.exe.

I need to know because I have one application that intervenes with the start . command, which I use extensively in Powershell (when working with a Git repository).

share|improve this question
    
If I remember, start checks first the working directory then the %PATH% variables by order. So yes it should resolve. – Doktoro Reichard Sep 2 '13 at 8:57
up vote 1 down vote accepted

You're looking for the where command.

C:\Users\gronostaj>where grep
C:\MinGW\msys\1.0\bin\grep.exe
C:\FPC\2.6.0\bin\i386-Win32\grep.exe
C:\Program Files (x86)\Git\bin\grep.exe

First one is executed when you type its name.

And remember that current working directory always has priority over PATH in Windows.

C:\Program Files (x86)\Git\bin>where grep
C:\Program Files (x86)\Git\bin\grep.exe
C:\MinGW\msys\1.0\bin\grep.exe
C:\FPC\2.6.0\bin\i386-Win32\grep.exe
share|improve this answer
    
Okay, that indeed works. However, where does the start command comes from? Because where start yields INFO: Could not find files for the given pattern(s). – Snake Sep 2 '13 at 9:08
    
start isn't a program, but a built-in command of cmd/Powershell (so are copy, del etc.). But the point is, if you want to for example start notepad, then where notepad will tell you which notepad it will be. – gronostaj Sep 2 '13 at 9:11
    
Note that where.exe returns all the paths where it finds the executable, while the interpreter will use only the first one. You should reckon with that or use which.exe. – Vlastimil Ovčáčík Sep 2 '13 at 12:49

Assuming PATH is the environment variable, use $exeLocation = Get-Command $exename | Select -Expand Path

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .