Se dois diretórios PATH separados contiverem um executável com o mesmo nome, como o Windows escolherá?

2

Estou no processo de atualização do PEAR (PHP) no meu sistema. O script de upgrade está me encorajando a adicionar ".. \ PHP \ PEAR" ao meu PATH para que eu possa usar o "pear.bat". No entanto, eu já posso usar o pear.bat.

Olhando no meu PATH, vejo que não tenho nenhum diretório PEAR, apenas meu diretório PHP. Abrindo meu diretório PHP, vejo que há um "pear.bat" na base. Mas também há um pear.bat na subpasta PEAR do PHP. Eu estou querendo saber se eu borked uma instalação PEAR.

Eu divago. Então, se eu deixar .. \ PHP no meu caminho, mas também adicionar .. \ PHP \ PEAR - ambos com um "pear.bat" neles - qual deles o Windows "escolher"? Como o Windows decide?

    
por Coldblackice 16.11.2012 / 09:37

2 respostas

3

O primeiro jogo vence. O pear.bat no diretório que vem primeiro no %PATH% é aquele que é executado:

  • PATH=..\PHP\PEAR;..\PHP : ..\PHP\PEAR\pear.bat é executado
  • PATH=..\PHP;..\PHP\PEAR : ..\PHP\pear.bat é executado
por 16.11.2012 / 10:14
3

De link :

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.

De acordo, isso se aplica ao Windows XP (não consigo encontrar nenhuma informação sobre outras versões do Windows), mas não acho que esse comportamento tenha mudado.

EDIT: Eu poderia encontrar algumas informações para o Windows Server 2008 e Vista aqui: link (quase o mesmo texto acima):

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.

que parece confirmar a suposição de que o comportamento não mudou nas versões do Windows.

    
por 16.11.2012 / 10:15