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.

I'm in the process of upgrading PEAR (PHP) on my system. The upgrade script is encouraging me to add "..\PHP\PEAR" to my PATH so that I can use "pear.bat". However, I already am able to use pear.bat.

Looking in my PATH, I see that I don't have any PEAR directories, only my PHP directory. Opening my PHP directory, I see that there's a "pear.bat" in the base. But there's also a pear.bat in the PEAR subfolder of PHP. I'm wondering if I borked a PEAR install.

I digress. So if I leave ..\PHP in my path, but also add ..\PHP\PEAR -- both of which have a "pear.bat" in them -- which one will Windows "choose"? How does Windows decide?

share|improve this question
    
You could just try it and see. I would expect that since PATH is an ordered list, the first one it found would be used. –  martineau Nov 16 '12 at 8:48
add comment

2 Answers 2

up vote 3 down vote accepted

First match wins. The pear.bat in the directory that comes first in the %PATH% is the one that is executed:

  • PATH=..\PHP\PEAR;..\PHP: ..\PHP\PEAR\pear.bat is executed
  • PATH=..\PHP;..\PHP\PEAR: ..\PHP\pear.bat is executed
share|improve this answer
add comment

From http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/path.mspx?mfr=true:

Two or more identical file names in the path

If you have two or more files in the command path that have the same file name and extension, Windows XP searches for the specified file name first in the current directory, and then it searches the directories in the command path in the order in which they are listed in PATH.

Agreed, this applies to Windows XP (I can't find any information about other Windows versions), but I don't think this behavior has changed.

EDIT: I could find some information for Windows Server 2008 and Vista here: http://technet.microsoft.com/en-us/library/cc753427%28v=ws.10%29.aspx (almost same text as above):

If two or more files in the command path have the same file name and extension, path first searches for the specified file name in the current directory. Then it searches the directories in the command path in the order that they are listed in the PATH environment variable.

which seems to confirm the assumption that the behavior hasn't changed across Windows versions.

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.