은 거기에 해당하는'창문에 명령행?
-
08-07-2019 - |
문제
나는 때로는이 경로 문제 중 하나는 나 자신의 cmd 스크립트가 숨겨져(그림)에 의하여 다른 프로그램(이 경로에),하고 싶을 찾을 수 있의 전체 경로로그램에는 Windows 명령 라인,주어진 이름이 있습니다.
은 거기에 상응하는 유닉스령'는'?
On UNIX, which command
인쇄물의 전체 경로 주어진 명령을 쉽게 찾을 수 있 및 수리 이 숨기는 문제입니다.
해결책
Windows Server 2003 이상 (예 : Windows XP 32 비트 이후) where.exe
어떤 일을하는 프로그램 which
실행 가능한 명령뿐만 아니라 모든 유형의 파일과 일치하지만. (내장 된 쉘 명령과 일치하지 않습니다 cd
.) 와일드 카드도 받아 들일 것입니다 where nt*
귀하의 모든 파일을 찾습니다 %PATH%
이름이 시작된 현재 디렉토리 nt
.
노력하다 where /?
도와주기 위해.
Windows PowerShell은 정의합니다 where
별칭으로 그만큼 Where-Object
cmdlet, 당신이 원한다면 where.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
사용하려는 환경 변수 (물론 경로 형식)를 대체 할 수 있기 때문입니다.
그리고 Windows 자체의 모든 확장을 처리 할 수있는 것을 원한다면 (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 CMDLETS, 기능, 별칭, 사용자 정의 실행 파일이있는 파일을 통해 $Env:PATHEXT
, 현재 쉘에 대해 정의 된 등 (Bash 's와 매우 유사하다 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
...
맞춤형 실행 파일 찾기
다른 비 창의 실행 파일 (파이썬, 루비, 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 설치(내가 추천한다),사용할 수 있습니다 다음과 같은 명령을 거친 것과 동일(대신 프로그램에 대한 귀하의 실행 파일의 이름):
($Env:Path).Split(";") | Get-ChildItem -filter programName*
더 여기에 있습니다:내 Manwich!PowerShell 는
그만큼 gnuwin32 도구가 있습니다 which
, 다른 유닉스 도구와 함께.
Windows CMD에서 which
전화 where
:
$ where php
C:\Program Files\PHP\php.exe
Cygwin 해결책입니다. 타사 솔루션을 사용하지 않는다면 Cygwin이 갈 길입니다.
Cygwin은 Windows 환경에서 *nix의 편안함을 제공합니다 (Windows 명령 쉘에서 사용하거나 선택한 *nix 쉘을 사용할 수 있습니다). 그것은 당신에게 많은 *nix 명령을 제공합니다 ( which
) Windows의 경우, 해당 디렉토리 만 포함시킬 수 있습니다. PATH
.
PowerShell에서는 그렇습니다 gcm
, 다른 명령에 대한 형식의 정보를 제공합니다. 실행 파일로의 경로 만 검색하려면 사용하십시오. .Source
.
예를 들어: gcm git
또는 (gcm git).Source
tidbits :
- Windows XP에서 사용할 수 있습니다.
- PowerShell 1.0 이후 제공됩니다.
gcm
별명입니다Get-Command
cmdlet.- 매개 변수가 없으면 호스트 쉘이 제공하는 사용 가능한 모든 명령을 나열합니다.
- 사용자 정의 별명을 만들 수 있습니다
Set-Alias which gcm
그리고 다음과 같이 사용하십시오.(which git).Source
. - 공식 문서 : https://technet.microsoft.com/en-us/library/ee176842.aspx
여기에서 unxutils를 얻으십시오. http://sourceforge.net/projects/unxutils/
Windows 플랫폼의 금은 모든 Nice Unix 유틸리티를 표준 Windows DO에 넣습니다. 몇 년 동안 사용해 왔습니다.
그것은 ''포함 된 ''가 있습니다. 그러나 사례에 민감합니다.
NB : 설치하려면 zip을 어딘가에 폭발시키고 ... unxutils usr local wbin 를 시스템 경로 Env 변수에 추가합니다.
'파워 쉘 프로필에' '라는 기능이 있습니다.
function which {
get-command $args[0]| format-list
}
출력의 모습은 다음과 같습니다.
PS C:\Users\fez> which python
Name : python.exe
CommandType : Application
Definition : C:\Python27\python.exe
Extension : .exe
Path : C:\Python27\python.exe
FileVersionInfo : File: C:\Python27\python.exe
InternalName:
OriginalFilename:
FileVersion:
FileDescription:
Product:
ProductVersion:
Debug: False
Patched: False
PreRelease: False
PrivateBuild: False
SpecialBuild: False
Language:
무료 파스칼 컴파일러를 찾을 수 있다면이를 컴파일 할 수 있습니다. 적어도 그것은 작동하고 필요한 알고리즘을 보여줍니다.
program Whence (input, output);
Uses Dos, my_funk;
Const program_version = '1.00';
program_date = '17 March 1994';
VAR path_str : string;
command_name : NameStr;
command_extension : ExtStr;
command_directory : DirStr;
search_dir : DirStr;
result : DirStr;
procedure Check_for (file_name : string);
{ Check existence of the passed parameter. If exists, then state so }
{ and exit. }
begin
if Fsearch(file_name, '') <> '' then
begin
WriteLn('DOS command = ', Fexpand(file_name));
Halt(0); { structured ? whaddayamean structured ? }
end;
end;
function Get_next_dir : DirStr;
{ Returns the next directory from the path variable, truncating the }
{ variable every time. Implicit input (but not passed as parameter) }
{ is, therefore, path_str }
var semic_pos : Byte;
begin
semic_pos := Pos(';', path_str);
if (semic_pos = 0) then
begin
Get_next_dir := '';
Exit;
end;
result := Copy(Path_str, 1, (semic_pos - 1)); { return result }
{ Hmm! although *I* never reference a Root drive (my directory tree) }
{ is 1/2 way structured), some network logon software which I run }
{ does (it adds Z:\ to the path). This means that I have to allow }
{ path entries with & without a terminating backslash. I'll delete }
{ anysuch here since I always add one in the main program below. }
if (Copy(result, (Length(result)), 1) = '\') then
Delete(result, Length(result), 1);
path_str := Copy(path_str,(semic_pos + 1),
(length(path_str) - semic_pos));
Get_next_dir := result;
end; { Of function get_next_dir }
begin
{ The following is a kludge which makes the function Get_next_dir easier }
{ to implement. By appending a semi-colon to the end of the path }
{ Get_next_dir doesn't need to handle the special case of the last entry }
{ which normally doesn't have a semic afterwards. It may be a kludge, }
{ but it's a documented kludge (you might even call it a refinement). }
path_str := GetEnv('Path') + ';';
if (paramCount = 0) then
begin
WriteLn('Whence: V', program_version, ' from ', program_date);
Writeln;
WriteLn('Usage: WHENCE command[.extension]');
WriteLn;
WriteLn('Whence is a ''find file''type utility witha difference');
Writeln('There are are already more than enough of those :-)');
Write ('Use Whence when you''re not sure where a command which you ');
WriteLn('want to invoke');
WriteLn('actually resides.');
Write ('If you intend to invoke the command with an extension e.g ');
Writeln('"my_cmd.exe param"');
Write ('then invoke Whence with the same extension e.g ');
WriteLn('"Whence my_cmd.exe"');
Write ('otherwise a simple "Whence my_cmd" will suffice; Whence will ');
Write ('then search the current directory and each directory in the ');
Write ('for My_cmd.com, then My_cmd.exe and lastly for my_cmd.bat, ');
Write ('just as DOS does');
Halt(0);
end;
Fsplit(paramStr(1), command_directory, command_name, command_extension);
if (command_directory <> '') then
begin
WriteLn('directory detected *', command_directory, '*');
Halt(0);
end;
if (command_extension <> '') then
begin
path_str := Fsearch(paramstr(1), ''); { Current directory }
if (path_str <> '') then WriteLn('Dos command = "', Fexpand(path_str), '"')
else
begin
path_str := Fsearch(paramstr(1), GetEnv('path'));
if (path_str <> '') then WriteLn('Dos command = "', Fexpand(path_str), '"')
else Writeln('command not found in path.');
end;
end
else
begin
{ O.K, the way it works, DOS looks for a command firstly in the current }
{ directory, then in each directory in the Path. If no extension is }
{ given and several commands of the same name exist, then .COM has }
{ priority over .EXE, has priority over .BAT }
Check_for(paramstr(1) + '.com'); { won't return if file is found }
Check_for(paramstr(1) + '.exe');
Check_for(paramstr(1) + '.bat');
{ Not in current directory, search through path ... }
search_dir := Get_next_dir;
while (search_dir <> '') do
begin
Check_for(search_dir + '\' + paramstr(1) + '.com');
Check_for(search_dir + '\' + paramstr(1) + '.exe');
Check_for(search_dir + '\' + paramstr(1) + '.bat');
search_dir := Get_next_dir;
end;
WriteLn('DOS command not found: ', paramstr(1));
end;
end.
내가 Windows에서 찾은 가장 좋은 버전은 Joseph Newcomer의 "Whereis"유틸리티이며,이 유틸리티는 (소스와 함께) 그의 사이트.
"Whereis"의 개발에 관한 기사는 읽을 가치가 있습니다.
인터넷에서 찾을 수있는 Win32 Unix 포트 중 어느 것도 Satistactory가 아닙니다. 모두 이러한 단점이 하나 이상 있기 때문입니다.
- Windows Pathext 변수에 대한 지원이 없습니다. (경로를 스캔하기 전에 각 명령에 암시 적으로 추가 된 확장 목록을 정의하고 순서대로 정의합니다.) (많은 TCL 스크립트를 사용하고 공개적으로 사용 가능한 도구를 찾을 수 없습니다.)
- cmd.exe 코드 페이지를 지원하지 않으므로 ASCII가 아닌 문자가있는 경로를 잘못 표시 할 수 있습니다. (나는 그것에 매우 민감합니다.
- cmd.exe 및 powerShell 명령 줄의 고유 한 검색 규칙에 대한 지원이 없습니다. (공개적으로 사용 가능한 도구가 없음 PowerShell 창에는 .ps1 스크립트가 있지만 CMD 창에는 없습니다!)
그래서 나는 결국 위의 모든 것을 올바르게 부패시키는 내 자신의 글을 썼습니다.
거기에서 사용 가능 :http://jf.larvoire.free.fr/progs/which.exe
이 배치 파일은 CMD 변수 처리를 사용하여 경로에서 실행되는 명령을 찾습니다. 참고 : 현재 디렉토리는 항상 경로 전에 수행됩니다.
@echo off
echo.
echo PathFind - Finds the first file in in a path
echo ======== = ===== === ===== ==== == == = ====
echo.
echo Searching for %1 in %path%
echo.
set a=%~$PATH:1
If "%a%"=="" (Echo %1 not found) else (echo %1 found at %a%)
보다 set /?
도와주기 위해.
먼저 GIT를 설치할 수 있습니다 GIT 다운로드, 그런 다음 git bash를 열고 다음을 입력합니다.
which app-name
Cygwin의 가벼운 버전 인 Gow (Windows의 GNU)를 사용하고 있습니다. Github에서 가져갈 수 있습니다 여기.
GOW (GNU on Windows)는 Cygwin에 대한 가벼운 대안입니다. 기본 Win32 Binaries로 컴파일 된 약 130 개의 매우 유용한 오픈 소스 UNIX 응용 프로그램을 설치하는 편리한 Windows 설치 프로그램을 사용합니다. 옵션에 따라 100MB 이상을 실행할 수있는 Cygwin과 달리 가능한 한 약 10MB로 설계되었습니다. - 설명 정보 (Brent R. Matzelle)
GOW에 포함 된 명령 목록의 스크린 샷 :
Ned Batchelder와 유사한 도구를 만들었습니다.
내 도구는 기본적으로 다양한 DLL 버전을 검색하기위한 것이지만 더 많은 정보 (날짜, 크기, 버전)가 표시되지만 Pathext를 사용하지 않습니다 (곧 도구를 업데이트하기를 바랍니다).
Windows XP 사용자 (없음 where
명령 내장), 나는 "Where"명령을 rubygem으로 작성했습니다. whichr
.
설치하려면 Ruby를 설치하십시오.
그 다음에
gem install whichr
다음과 같이 실행하십시오.
C :> whyr cmd_here
JPSOFT의 TCC 및 TCC/LE는 CMD.EXE 교체품입니다. OP의 질문과 관련하여 which
TCC 패밀리 명령 프로세서를위한 내장 명령입니다.
나는 그것을 사용했다 which
NPM의 모듈은 꽤 오랫동안 잘 작동합니다. https://www.npmjs.com/package/which훌륭한 멀티 플랫폼 대안입니다.
이제 나는 which
그것은 git과 함께 제공됩니다. 당신의 길에 추가하십시오 /usr/bin
보통 git의 경로 C:\Program Files\Git\usr\bin\which.exe
. 그만큼 which
이진이있을 것입니다 C:\Program Files\Git\usr\bin\which.exe
. 더 빠르고 예상대로 작동합니다.
이 시도
set a=%~$dir:1
If "%for%"=="" (Echo %1 not found) else (echo %1 found at %a%)