Sonntag, 25. Dezember 2011

Goovy & Unix: How to find a program?

How to find out in Groovy whether a program is installed?

I've tried this:

// Check for availability of "formail", which should be included in packages for "procmail"
def formailPath = 'which formail'.execute().text.trim()
assert formailPath > '', 'Programm "formail" is needed. Please install package procmail'

and it worked quite well, since the expression 'which formail'.execute().text.trim() returns either the empty string or the path to the executable.