Ho un which.bat su Windows 7,
@echo off
REM This bat searches a file in PATH list to see whether a file can be found.
REM If found, it shows the file's full path.
REM which.bat gcc.exe
REM shows
REM gcc.exe is found: D:\GMU\MinGW2\bin\gcc.exe
REM
REM Note: Filename extension is significant in the search. E.g. If you run
REM which.bat gcc
REM gcc.exe will not be matched.
IF "%1" == "" goto END
IF "%~$PATH:1" == "" (
echo %1 is not found in any directories from PATH env-var.
) ELSE (
echo %1 is found: %~$PATH:1
)
:END
Questo pipistrello funziona bene fino a quando ho trovato uno strano comportamento di oggi.
è presente un file O:\temp\pfiles (x86)\mystuff.txt
, e PATH ha un contenuto:
PATH=O:\temp\pfiles (x86);D:\CmdUtils
esecuzione which mystuff.txt
, ho ottenuto il molto strano uscita:
\mystuff.txt was unexpected at this time.
Dopo un po 'rovistando , Trovo che il (x86)
nel nome della directory causa th e problema Per risolvere il problema, devo aggiungere citazioni al echo
, in questo modo:
echo %1 is found: "%~$PATH:1"
L'aspetto negativo di tale tweak è evidente: Le citazioni vengono stampate a schermo che non è sempre desiderato nel parere del programmatore.
Qualcuno può aiutare a spiegare questo strano comportamento?
Trovo questo problema perché nel mio ambiente reale, ho alcuni percorsi come C:\Program Files (x86)\Common Files\NetSarang
in PERCORSO, che presentano esattamente lo stesso sintomo.
Grazie per avermi permesso di conoscere. '' where.exe'' è fantastico. Sto usando which.bat da Windows XP dove non c'è ancora '' where.exe''. –
buone informazioni ... ma se stai cercando un 'eseguibile' e non fornisci alcuna estensione, allora non funziona ... usa 'where.exe' allora ... o 'which' se sei in linux ... o installa Cygwin e usa 'which' ... funziona alla grande !!! – ZEE