How to test if an executable exists in the %PATH% from a windows batch file?

后端 未结 9 616
暖寄归人
暖寄归人 2020-12-22 20:33

I\'m looking for a simple way to test if an executable exists in the PATH environment variable from a Windows batch file.

Usage of external tools not provided by th

9条回答
  •  遥遥无期
    2020-12-22 20:59

    Here is a simple solution that attempts to run the application and handles any error afterwards.

    file.exe /?  2> NUL
    IF NOT %ERRORLEVEL%==9009 ECHO file.exe exists in path
    

    Error code 9009 usually means file not found.

    The only downside is that file.exe is actually executed if found (which in some cases is not desiderable).

提交回复
热议问题