windows - विंडोज कमांड लाइन पर 'कौन सा' के बराबर है?
command-line path-variables (14)
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
यह पावरहेल cmdlets, फ़ंक्शंस, उपनाम, कस्टम एक्जिक्यूटिव एक्सटेंशन के साथ फ़ाइलों को $Env:PATHEXT
, आदि के माध्यम से वर्तमान खोल के लिए परिभाषित किया गया है (बाश के type -a foo
के समान) - यह अन्य टूल्स जैसे अन्य उपकरणों की तुलना में बेहतर हो जाता है where.exe
, which.exe
, आदि जो इन PowerShell कमांड से अनजान हैं।
आप जल्दी से sal which gcm
साथ उपनाम स्थापित कर सकते हैं sal which gcm
( set-alias which get-command
का संक्षिप्त रूप set-alias which get-command
) है।
जैसे-जैसे मुझे कभी-कभी पथ की समस्या होती है, जहां मेरी अपनी सीएमडी स्क्रिप्ट्स में से एक किसी अन्य प्रोग्राम (पहले पथ पर) छिपी हुई है (छाया), मैं विंडोज कमांड लाइन पर किसी प्रोग्राम के लिए पूर्ण पथ ढूंढने में सक्षम होना चाहता हूं बस इसका नाम
क्या यूनिक्स कमांड 'कौन सा' के बराबर है?
यूनिक्स पर, which command
इन छायादार समस्याओं को आसानी से ढूंढने और मरम्मत करने के लिए दिए गए आदेश के पूर्ण पथ को प्रिंट करता है।
आप पहले https://git-scm.com/download/win से गिट स्थापित कर सकते हैं, फिर गिट बैश खोलें और टाइप करें
which app-name
आश्चर्यचकित है कि किसी ने अभी तक समाधान के रूप में साइगविन का उल्लेख नहीं किया है। यदि आपको किसी तृतीय-पक्ष समाधान का उपयोग करने में कोई फर्क नहीं पड़ता है, तो साइगविन जाने का रास्ता है।
सिग्विन आपको विंडोज वातावरण में * निक्स का आराम देता है (और आप इसे अपने विंडोज कमांड शैल में उपयोग कर सकते हैं, या अपनी पसंद के * निक्स शैल का उपयोग कर सकते हैं)। यह आपको विंडोज के लिए * निक्स कमांड (जैसे) का पूरा मेजबान देता है, और आप केवल उस निर्देशिका को अपने PATH
में शामिल कर सकते हैं।
जबकि विंडोज के बाद के संस्करणों में एक कमांड है, आप पर्यावरण परिवर्तक संशोधक का उपयोग कर 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 (जैसे विंडोज स्वयं करता है) में सभी एक्सटेंशन को संभाल सकता है, तो यह चाल है:
@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
यह वास्तव में सभी संभावनाओं को वापस करता है लेकिन आप विशिष्ट खोज नियमों के लिए इसे आसानी से ट्विक कर सकते हैं।
डुनो अगर यह मदद करता है। उत्तर के रूप में पोस्ट किया गया क्योंकि मुझे नहीं पता कि टिप्पणियों में कोड कैसे प्रारूपित करें (सहायता?)
यदि आप एक मुफ्त पास्कल कंपाइलर पा सकते हैं, तो आप इसे संकलित कर सकते हैं, या मुझे ईमेल कर सकते हैं और मैं एक को खोदने का प्रयास कर सकता हूं, या exe को वापस भेज सकता हूं या इसे कहीं पोस्ट कर सकता हूं। मैं कोड पोस्ट करता हूं, जैसा कि खराब है, क्योंकि कम से कम यह काम करता है और एल्गोरिदम आवश्यक बनाता है।
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 existance 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 thru 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.
पथ में निष्पादित आदेश को खोजने के लिए यह बैच फ़ाइल सीएमडी वैरिएबल हैंडलिंग का उपयोग करती है। नोट: कि वर्तमान निर्देशिका हमेशा पथ से पहले की जाती है) और जिस पर निर्भर करता है कि किस एपीआई कॉल का उपयोग किया जाता है, अन्य स्थानों को पथ के पहले / बाद में खोजा जाता है।
@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 /?
देखें set /?
मदद के लिए।
मेरे पास 'Power' नामक मेरे PowerShell प्रोफ़ाइल में एक फ़ंक्शन है
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:
मैं GOW (विंडोज़ पर जीएनयू) का उपयोग कर रहा हूं जो साइगविन का एक हल्का संस्करण है। आप इसे here. जिथब से पकड़ सकते here.
गो (विंडोज़ पर जीएनयू) सिगविन के हल्के विकल्प हैं। यह एक सुविधाजनक विंडोज इंस्टालर का उपयोग करता है जो लगभग 130 बेहद उपयोगी ओपन सोर्स यूनिक्स अनुप्रयोगों को मूल Win32 बाइनरी के रूप में संकलित करता है। इसे जितना संभव हो उतना छोटा बनाया जा सकता है, लगभग 10 एमबी, सिग्विन के विपरीत जो विकल्प के आधार पर 100 एमबी से अधिक अच्छी तरह से चला सकता है। - विवरण के बारे में (ब्रेंट आर Matzelle)
गाय में शामिल कमांड की सूची का स्क्रीनशॉट।
यदि आपके पास PowerShell इंस्टॉल है (जो मैं अनुशंसा करता हूं), तो आप निम्न आदेश का उपयोग किसी न किसी समकक्ष (आपके निष्पादन योग्य नाम के लिए substitue प्रोग्राम नाम) के रूप में कर सकते हैं:
($Env:Path).Split(";") | Get-ChildItem -filter programName*
यहां और अधिक: http://www.codeassassin.com/blog/PermaLink,guid,fd1967d1-f844-4e29-82e2-f2d6424b4ef9.aspx
यहां से अनैतिकताएं प्राप्त करें: http://sourceforge.net/projects/unxutils/
विंडोज प्लेटफॉर्म पर सोना, एक मानक विंडोज डॉस पर सभी अच्छी यूनिक्स उपयोगिताओं को रखता है। वर्षों से इसका इस्तेमाल कर रहे थे।
इसमें एक 'कौन सा' शामिल है। ध्यान दें कि हालांकि यह मामला संवेदनशील है।
एनबी: इसे स्थापित करने के लिए कहीं ज़िप को विस्फोट करें और ... \ UnxUtils \ usr \ local \ wbin \ आपके सिस्टम पथ env चर में उपयोग करता है।
विंडोज सर्वर 2003 और बाद में (यानी विंडोज एक्सपी 32 बिट के बाद कुछ भी) where.exe
प्रोग्राम प्रदान करता है जो कुछ करता है which
करता है, हालांकि यह सभी प्रकार की फाइलों से मेल खाता है, न केवल निष्पादन योग्य आदेश। (यह cd
जैसे अंतर्निहित शेल कमांड से मेल नहीं खाता है।) यह वाइल्डकार्ड भी स्वीकार करेगा, इसलिए where nt*
आपके %PATH%
और वर्तमान निर्देशिका में सभी फाइलें पाता है जिनके नाम nt
शुरू होते हैं।
कोशिश करें where /?
मदद के लिए।
ध्यान दें कि Windows PowerShell Where-Object
cmdlet के लिए उपनाम के रूप में परिभाषित करता है, इसलिए यदि आप where.exe
चाहते हैं, तो आपको .exe
एक्सटेंशन को छोड़ने के बजाय पूर्ण नाम टाइप करना होगा।
विंडोज सीएमडी में which
कहता है:
$ where php
C:\Program Files\PHP\php.exe
विंडोज़ पावरहेल में:
set-alias which where.exe
स्टॉक विंडोज में नहीं, लेकिन यह यूनिक्स के लिए सेवाओं द्वारा प्रदान किया जाता है और इस तरह की एक ही चीज को पूरा करने के आसपास कई सरल बैच स्क्रिप्ट चलती हैं।