Troll the Legacy
Troll the Legacy

Reputation: 715

Check a program existence in PATH

I'm running batch scripts (usually from Visual Studio) and want to check that some program available through the PATH and if not - then show a message. Simple file checking like

if exist mingw32-make (echo "exists") else (echo "not exists")

not working - shell always thinking that app is not exists (maybe because it not looking into PATH).
How to do this right and clean?

Upvotes: 0

Views: 755

Answers (1)

Stephan
Stephan

Reputation: 56180

where checks, if the given file exists within the path (or on the current working folder %cd%) and gives either the full path(s) or an error message. Both you don't need - just the errorlevel:

where mingw32-make >nul 2>&1
if errorlevel 1 (echo "not exists") else (echo "exists")

or as a shortcut:

where /q mingw32-make && echo found || echo not found

Upvotes: 2

Related Questions