Reputation: 282775
On linux you can use command
; how can I determine if a command exists on Windows?
where
does not appear to work on cd
; I'm looking for something that will work even on the built-in commands.
Upvotes: 2
Views: 3365
Reputation: 36308
Personally, I'd probably run each command separately, and do the logic in PHP. (You might also want to consider whether it is necessary to test for the existence of the internal commands at all; they haven't really changed much in the last couple of decades.)
However, this should work:
cmd /c "(help FOO > nul || exit 0) && where FOO > nul 2> nul"
This will return 0 if the command FOO
is found, 1 if it is not.
Upvotes: 5