I have a command’s name and I need to check if this command is internal. How can I do it in a batch script?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
So after a lot of tweaking, and thanks to the help of @Andriy M, it finally works.
OLD SOLUTION
You can use
where. If it fails, the command is probably internal. If it succeeds, you get the executable path that proves it’s not internal.EDIT: As the comments suggest, this might not be the best solution if you’re looking for portability and not just research. So here’s another possible solution.
Set
%PATH%to nothing soHELPcan’t find anything and then runHELPon the command you’re trying to check.This might still fail if the command doesn’t have help.
EDIT 2: Never mind, this won’t work either. Both cases return
%ERRORLEVEL%=1.