Skip to content
Advertisement

How to check existence of a program in the path

I’m writing a program in scala which call:

JavaScript

I want to check if “svn” is available from the commandline (ie. it is reachable in the PATH). How can I do this ?

PS: My program is designed to be run on windows

Advertisement

Answer

Here’s a Java 8 solution:

JavaScript

Replace anyMatch(...) with filter(...).findFirst() to get a fully qualified path.


Here’s a cross-platform static method that compares common executable extensions:

JavaScript

This should address most of the critiques for the first solution. Aside, iterating over the PATHEXT system environment variable would avoid hard-coding extensions, but comes with its own drawbacks.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement