How can I print full path of an executable command in Windows?

10

4

At the moment when trying to run tf command and/or any other run-able command, I need to open Visual Studio Command to get it executable. I like to use the normal console and/or the alternative console but failed to call tf.

So, I need to print the full path of tf and any runable-command but don't know how to do so.

Please help.

Nam G VU

Posted 2011-02-21T07:35:23.780

Reputation: 10 255

The poster is looking for the equivalent of the "which" command in some Unix shells, e.g. "which grep" prints the full path of the grep command that the shell will execute in response to you typing "grep" without a path. I'm looking for this too. – None – 2011-03-27T06:45:19.050

Answers

13

I'm not really sure what you are asking, but judging by your comments, you may be looking for where.

where foo

where foo | clip

The second example will place the whole path into the clipboard.

If I remember correctly, where.exe needs to be added to XP/2003 from the Windows 2003 Resource Kit or XP Support Tools.

paradroid

Posted 2011-02-21T07:35:23.780

Reputation: 20 970

2

It comes preinstalled with Windows 7. There is also a script for older Windows versions.

– user1686 – 2011-03-27T14:17:18.343

There is also a where.exe in UnxUtils, along with lot of useful Unix commands. – PhiLho – 2011-03-29T09:25:22.353

@PhiLho: The original Unix version is which. – paradroid – 2011-03-29T12:35:10.463

ouch, where.exe lives in system32, my bad... Funnily, I just tried them to find java.exe, where points to the JDK path (that's the one Windows finds) while which points to system32, earlier in the path. But it doesn't exist there, there might be a hardlink there, or something similar. Well, back to the topic, which, roughly similar to where, can be found in a free package. – PhiLho – 2011-04-09T07:22:16.883

1

where.exe as mentioned in one of the comments does come with Windows 7 and higher. Another thing to note is that where only searches the %PATH% so if your program isn't in the path it won't help you locate it.

Another problem is if you happen to be trying to invoke it from within a PowerShell prompt you NEED to include the .exe portion, as "where" is an alias for Where-Object which is NOT what you want, and leads to empty results with success codes that obviously don't tell you where the application you want is actually located.

This took me a few tries to figure out, and only appending -? which triggered help on what the alias actually resolved to clued me in.

Per your question, the reason tf works from within the Visual Studio application/console, there is a specific shortcut they include to launch a Visual Studio console because it adds the application's folders to the PATH when launched.

You can define your own shortcut to inject the program's directory into your PATH, or just open the Start Menu, type "env" and click the shortcut "Edit environment variables for your account" (or the system one, but that requires you to click on the Environment Variables button), then add a new PATH variable at the top under User Variables if it doesn't exist, or if it already exists add a ; before your entry and then the complete folder path where the program you want to call from the command line lives. E.g. double click the PATH entry (case doesn't matter much on Windows) to edit and change it to C:\ExistingPathItem\bin;C:\Program Files (x86)\Microsoft\Visual Studio 2020\bin

dragon788

Posted 2011-02-21T07:35:23.780

Reputation: 634

1

According to Microsoft, you should find tf in <drive>:\Program Files\Microsoft Visual Studio x\Common7\IDE.

(I've substituted x in the version because I don't know which version you're using.)


EDIT:

According to the Walkthrough: Working with Team Foundation Source Control from Command Line, (and assuming VS 2005), you can access the tools for TF at the following path:

<drive>:\Program Files\Microsoft Visual Studio 8\Common7\Tools

user3463

Posted 2011-02-21T07:35:23.780

Reputation:

@Potter: Thank you! How about any other run-able commands that were added in the system environment variable PATH? Should it be a quick command to print their full path? – Nam G VU – 2011-02-21T07:59:02.020

Are you talking about Team Foundation executables specifically? – None – 2011-02-21T08:01:22.373

@Potter: No. I'm talking about a general executable command. – Nam G VU – 2011-02-21T08:23:53.500