Consider the following PATH


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).

  • 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

You're looking for the where command.

C:\Users\gronostaj>where grep
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
  • 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

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.