Windows 명령 행에 ‘which’에 해당하는 것이 있습니까? 주어진 Windows

때때로 자신의 cmd 스크립트 중 하나가 다른 프로그램 (경로의 이전)에 의해 숨겨져있는 그림자 문제가 있기 때문에 주어진 Windows 명령 줄에서 프로그램의 전체 경로를 찾고 싶습니다. 그 이름 만

UNIX 명령 ‘which’에 해당하는 것이 있습니까?

UNIX에서는 which command이러한 섀도 잉 문제를 쉽게 찾아서 복구하기 위해 지정된 명령의 전체 경로를 인쇄합니다.



답변

Windows Server 2003 이상 (즉, Windows XP 32 비트 이후)은 실행 가능한 명령뿐만 아니라 모든 유형의 파일과 일치하지만 where.exe일부 기능을 수행 하는 프로그램을 제공 which합니다. (와 같은 내장 쉘 명령과는 일치하지 않습니다 cd.) 와일드 카드도 사용할 수 있으므로 현재 디렉토리에서 이름이로 시작하는 where nt*모든 파일을 찾습니다 .%PATH%nt

시도 where /?도움.

Windows PowerShell을가 정의하는 주 where에 대한 별칭으로 cmdlet은 , 그래서 당신이 원하는 경우에 , 당신은 생략하는 대신 전체 이름을 입력해야 확장.Where-Objectwhere.exe.exe


답변

이후 버전의 Windows에는 where명령이 있지만 다음과 같이 환경 변수 수정자를 사용하여 Windows XP에서도이를 수행 할 수 있습니다.

c:\> for %i in (cmd.exe) do @echo.   %~$PATH:i
   C:\WINDOWS\system32\cmd.exe

c:\> for %i in (python.exe) do @echo.   %~$PATH:i
   C:\Python25\python.exe

추가 도구가 필요하지 않으며 PATH사용하려는 환경 변수 (경로 형식)를 대체 할 수 있기 때문에 제한되지 않습니다 .


그리고 PATHEXT (Windows 자체와 마찬가지로)의 모든 확장을 처리 할 수 ​​있기를 원한다면이 트릭을 수행하십시오.

@echo off
setlocal enableextensions enabledelayedexpansion

:: Needs an argument.

if "x%1"=="x" (
    echo Usage: which ^<progName^>
    goto :end
)

:: First try the unadorned filenmame.

set fullspec=
call :find_it %1

:: Then try all adorned filenames in order.

set mypathext=!pathext!
:loop1
    :: Stop if found or out of extensions.

    if "x!mypathext!"=="x" goto :loop1end

    :: Get the next extension and try it.

    for /f "delims=;" %%j in ("!mypathext!") do set myext=%%j
    call :find_it %1!myext!

:: Remove the extension (not overly efficient but it works).

:loop2
    if not "x!myext!"=="x" (
        set myext=!myext:~1!
        set mypathext=!mypathext:~1!
        goto :loop2
    )
    if not "x!mypathext!"=="x" set mypathext=!mypathext:~1!

    goto :loop1
:loop1end

:end
endlocal
goto :eof

:: Function to find and print a file in the path.

:find_it
    for %%i in (%1) do set fullspec=%%~$PATH:i
    if not "x!fullspec!"=="x" @echo.   !fullspec!
    goto :eof

실제로 모든 가능성을 반환하지만 특정 검색 규칙에 따라 쉽게 조정할 수 있습니다.


답변

PowerShell에서의 Get-Command어느 곳에서나 실행 파일을 찾을 수 있습니다 $Env:PATH.

Get-Command eventvwr

CommandType   Name          Definition
-----------   ----          ----------
Application   eventvwr.exe  c:\windows\system32\eventvwr.exe
Application   eventvwr.msc  c:\windows\system32\eventvwr.msc

또한을 통해 사용자 정의 실행 파일의 확장자 PowerShell cmdlet을, 함수, 별칭, 파일을 찾아 $Env:PATHEXT(배쉬의 아주 가깝다 현재 쉘에 대해 정의 등 type -a foo) – 만드는 것이 더 나은 이동 – 다른 도구를 좋아하는 것보다 where.exe, which.exe등이 모르고있는 PowerShell 명령.

이름의 일부만 사용하여 실행 파일 찾기

gcm *disk*

CommandType     Name                             Version    Source
-----------     ----                             -------    ------
Alias           Disable-PhysicalDiskIndication   2.0.0.0    Storage
Alias           Enable-PhysicalDiskIndication    2.0.0.0    Storage
Function        Add-PhysicalDisk                 2.0.0.0    Storage
Function        Add-VirtualDiskToMaskingSet      2.0.0.0    Storage
Function        Clear-Disk                       2.0.0.0    Storage
Cmdlet          Get-PmemDisk                     1.0.0.0    PersistentMemory
Cmdlet          New-PmemDisk                     1.0.0.0    PersistentMemory
Cmdlet          Remove-PmemDisk                  1.0.0.0    PersistentMemory
Application     diskmgmt.msc                     0.0.0.0    C:\WINDOWS\system32\diskmgmt.msc
Application     diskpart.exe                     10.0.17... C:\WINDOWS\system32\diskpart.exe
Application     diskperf.exe                     10.0.17... C:\WINDOWS\system32\diskperf.exe
Application     diskraid.exe                     10.0.17... C:\WINDOWS\system32\diskraid.exe
...

사용자 정의 실행 파일 찾기

Windows 이외의 다른 실행 파일 (python, ruby, perl 등)을 찾으려면 해당 실행 파일의 확장명을 가진 파일 을 식별 할 수 있도록 해당 실행 파일의 파일 확장자를 PATHEXT환경 변수 (기본값은 .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.CPL)에 추가해야합니다 PATH. 으로 Get-Command이 변수를 존중, 그것은 목록의 사용자 정의 실행 파일을 확장 할 수 있습니다. 예 :

$Env:PATHEXT="$Env:PATHEXT;.dll;.ps1;.psm1;.py"     # temporary assignment, only for this shell's process

gcm user32,kernel32,*WASM*,*http*py

CommandType     Name                        Version    Source
-----------     ----                        -------    ------
ExternalScript  Invoke-WASMProfiler.ps1                C:\WINDOWS\System32\WindowsPowerShell\v1.0\Invoke-WASMProfiler.ps1
Application     http-server.py              0.0.0.0    C:\Users\ME\AppData\Local\Microsoft\WindowsApps\http-server.py
Application     kernel32.dll                10.0.17... C:\WINDOWS\system32\kernel32.dll
Application     user32.dll                  10.0.17... C:\WINDOWS\system32\user32.dll

sal which gcm(짧은 형식의 set-alias which get-command)을 사용 하여 별칭을 빠르게 설정할 수 있습니다 .

자세한 내용과 예는에 대한 온라인 도움말에서 찾을 수 있습니다 Get-Command.


답변

Windows PowerShell에서 :

set-alias which where.exe


답변

PowerShell을 설치 한 경우 (권장) 다음 명령을 대략적으로 동등한 것으로 사용할 수 있습니다 (실행 파일 이름 대신 programName을 사용).

($Env:Path).Split(";") | Get-ChildItem -filter programName*

자세한 내용은 여기 :
My Manwich! PowerShell 어느


답변

GnuWin32의 도구가 which다른 유닉스 도구의 전체 슬루와 함께.


답변

Windows CMD which호출에서 where:

$ where php
C:\Program Files\PHP\php.exe