@WHICH[]

#1
Ever need to know if a given command is available within your batch file at runtime? This function lets you know if a command is available and what it's source is by using the internal WHICH command as a function:

Code:
which   =%@exec[@set _which=%@left[3,%@word[3,%@execstr[which %1]]]]%@if[%_which eq int,1,%@if[%_which eq ali,2,%@if[%_which eq ext,3,%@if[%_which eq bat,4,%@if[%_which eq exe,5,%@if[%_which eq wit,6,%@if[%_which eq unk,-1,0]]]]]]]%+unset _which
The return value lets you know the type:
1: internal command
2: alias
3: external
4: batch
5: Executable extenstion
6: Windows file association
-1: unknown

{yes, it's a crazy, long function and I wish Rex would incorporate it directly into the API because I use it all the time}
 
Jul 1, 2008
81
0
71
Montreal
#2
{yes, it's a crazy, long function and I wish Rex would incorporate it directly into the API because I use it all the time}
Here's a shorter version:
Code:
%@dec[%@eval[%@index[unk xxx int ali ext bat exe wit,%@left[3,%@word[3,%@execstr[which %1]]]] / 4]]
 
#3
If you don't care where the command is located (because you already know by looking at the name), this works for me, assuming that the command name is %1:

(which %1 | ffind /E"external|alias|batch" /B >NUL) || (echo ERROR! %1 is not available! Exiting ... %+ quit)