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

后端 未结 9 648
暖寄归人
暖寄归人 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 21:23

    For those looking for a PowerShell option. You can use the Get-Command cmdlet passing two items. First give the current dir location with .\ prefixed, then give just the exe name.

    (Get-Command ".\notepad", "notepad" -ErrorAction Ignore -CommandType Application) -ne $null
    

    That will return true if found local or in system wide paths.

提交回复
热议问题