Platform discovery (Window or Linux) on groovy / grails

Is there any way to detect the platform (Window / Linux) where the website is running Groovy / Grails?

+26
grails platform-detection groovy
Jan 14 '11 at 8:35
source share
1 answer
System.properties['os.name'] 

will return the name of the OS, for example. "Windows XP". Therefore, if you want to find out if you work on Windows or not, you can do something like:

 if (System.properties['os.name'].toLowerCase().contains('windows')) { println "it Windows" } else { println "it not Windows" } 

As an alternative to org.apache.commons.lang.SystemUtils (from the Apache commons-lang project) provides some logical constants that provide the same information as the code above, e.g.

 SystemUtils.IS_OS_MAC SystemUtils.IS_OS_WINDOWS SystemUtils.IS_OS_UNIX 

More specific constants such as these are also available.

 SystemUtils.IS_OS_WINDOWS_2000 SystemUtils.IS_OS_SOLARIS SystemUtils.IS_OS_MAC_OSX 
+49
Jan 14 2018-11-11T00:
source share



All Articles