Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

If I type a command in the prompt, the command processor searches it in current path, and then (if not found) in the paths listed in PATH environment variable.

So is there a way to easily know in which exactly path my typed command was found? It could be useful it your command may appear in several system paths.

Batch file with a parameter of my command is accepted as a solution.

Then, since self-answer is not accepted with my reputation, this is the answer I've found:

I have found a hint to this here, in a post in MSDN blog where Path Manipulation in a Batch File is described. Actually, we create and call the batch file below:

@REM this file is called where.in.PATH.cmd

@ECHO %1
@ECHO %~$PATH:1

If you want to find which 'tf.exe' will be executed, you just type:

where.in.PATH.cmd tf.exe

The output is:

tf.exe
C:\Program Files\Microsoft Visual Studio 11.0\Common7\IDE\TF.exe

i.e. the only full path which is used to execute the typed tf.exe, unlikely the output of where standard command suggested in answers below.

share|improve this question
    
do something like "wmic process get commandline" will do the same thing not sure if this was what your are looking for though. –  tony roth Nov 21 '12 at 16:04

3 Answers 3

Under Linux environment, you can use the command which your_binary. For an equivalent under Windows, you can use the where command as explained in this post.

share|improve this answer
    
Sorry, I did not specify in subject that I meant Windows systems, just tagged. But there is no out-of-box command similar to where in Windows. Anyway, you’ll just leave this here :). –  moudrick Nov 21 '12 at 8:33
    
The Windows DOS command WHERE exists since Windows 2003 + :-) –  hot2use Nov 21 '12 at 8:48
    
@hot2use Indeed it does. But if you want someone other than the person who posted the answer or question you're making a comment under to see what you're typing, put the @ symbol in front of their name, so they get notified. –  HopelessN00b Nov 21 '12 at 9:00
    
Yes, you're right. SO now I'll have to accept the answer below. –  moudrick Nov 21 '12 at 9:04
    
Edit for previous comment: No, it does not help immediately. It shows the list of files by a mask, but then you have to review the output and the PATH variable to learn which of the paths in the output is the first in the variable. –  moudrick Nov 21 '12 at 9:18

WHERE is the closest thing you'll find on Windows, and it's included in all Windows OSes, starting with 2003.

where

share|improve this answer
    
Yes, it works. What I looked for is where "%PATH%:tf.*" This is the simplest way, I'll accept it. But I have found more complicated and less obvious way with batch parameter manipulation. I'll write self-answer then. –  moudrick Nov 21 '12 at 9:02
    
Edit for previous comment: No, it does not help immediately. It shows the list of files by a mask, but then you have to review the output and the PATH variable to learn which of the paths in the output is the first in the variable. Anyway, my reputation on serverfault is too low to increase rating of the answer to my own question :) I must note that the approach I found gives the answer to my question immewdiately. Of course, if you have the batch ready or remember the syntax by heart. –  moudrick Nov 21 '12 at 9:22
  • You can download procmon.exe from the Sysinternals Suite (Microsoft).
  • Run Procmon.exe
  • Then run your command.

You should see each and every access of anything to anywhere. I use procmon for debugging in such situations.

share|improve this answer
    
It helps if your command executes for long time. If it ends quickly, it is hardly applicable. –  moudrick Nov 21 '12 at 8:57
    
@moudrick Why so? Procmon captures everything in the pagefile and you should be able to catch even fast running batch files. Running procmon.exe for two seconds reveals 18'000 events. –  hot2use Nov 21 '12 at 9:09
    
If I understand correctly, it can show me the process information even after it has ended already? Well, I'll review this approach. Thanks anyway. –  moudrick Nov 21 '12 at 11:30
    
@moudrick It will show you what the individual executables were doing, which registry keys were accessed, the network point-to-point connections, file accesses (this is the one you are looking for) and other information. –  hot2use Nov 21 '12 at 12:24

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.