Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When I run an app from the DOS Prompt in Windows, the command in question is often not in the current directory, but is found via the PATH environment variable. What's the quickest way to find the path of the actual EXE that's being run?

share|improve this question
    
"path" gives you a list, you could check each manually. Though don't absent mindedly hit ; before return, or you might have to spend 10 minutes rebuilding your path, like I just did >_< –  Phoshi Sep 3 '09 at 9:17
add comment

4 Answers

up vote 5 down vote accepted

On Vista you can type the executable's name in search field in start menu, when it's displayed in results, r-click and select "Open file location" from menu.

If the program is still running and you are using Process explorer from Sysinternals you can r-click on executable in the the processes list and select properties. In the Image tab you have path to the executable.

Another way is to use Windows Powershell, use command "get-command executable" without quotes and you will get path for the executable you are looking for. Shortcut for the command is gcm, so use like this "gcm calc"

share|improve this answer
    
Accepting this answer, as it directly addresses my question. The Powershell approach seems like the quickest way too. :) Unfortunately... I want to find the path of an EXE after running a separate DOS batch file that modifies the PATH environment variable. In Powershell, running the batch file requires a separate cmd.exe to be run, which means the PATH in Powershell is unaffected and so my target exe (tf.exe) still can't be located. Still, I should've said that in my question. Just didn't think it was important at the time. :-/ –  Mal Ross Sep 3 '09 at 10:32
    
Using the taskmanager in Windows 7 (maybe Vista too), you can also right-click the process and choose "Open File Location". You don't need to install 3rd-party software like process explorer for this. If you know the processname, you can also type get-process processname | % { $_.path } to find the executable-path. However, this works not for every process. I haven't found the rule for that yet... –  wullxz May 23 '12 at 20:55
add comment

If you have cygwin installed, you could always use the 'which' command

C:> which notepad
/c/WINDOWS/system32/notepad
share|improve this answer
    
nice. but try "which dir"... –  nik Sep 3 '09 at 9:27
    
+1, I do like the idea -- just that it needs a unix environment. You can also use the UnixUtil binary. unxutils.sourceforge.net –  nik Sep 3 '09 at 9:39
    
There are several which implementations floating around which run without the Unix subsystem –  Xetius Sep 3 '09 at 9:43
add comment

You could try

CD \
dir /s command.*

or from explorer just do a search for the command name.

share|improve this answer
add comment

Try the following:

@rem file which.bat (must be placed somewhere in %PATH%)
@for %%e in (%PATHEXT%) do @for %%i in (%1%%e) do @if NOT "%%~$PATH:i"=="" echo %%~$PATH:i

When you type which notepad in commandline (cmd.exe):

C:\>which notepad
C:\Windows\System32\notepad.exe
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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