通过groovy / grails检测平台(Window或Linux) [英] Detecting the platform (Window or Linux) by groovy/grails
问题描述
System.properties ['os.name']
将返回操作系统的名称,例如Windows XP。因此,如果你想知道你是否在Windows上运行,你可以这样做:
if .properties ['os.name']。toLowerCase()。contains('windows')){
println它是Windows
} else {
println它不是Windows
$ / code>
或者, org.apache.commons.lang.SystemUtils
(来自 Apache commons-lang 项目)暴露了一些布尔常量,它们提供了与上述代码相同的信息,例如
SystemUtils.IS_OS_MAC
SystemUtils.IS_OS_WINDOWS
SystemUtils.IS_OS_UNIX
这些更具体的常量也可用
SystemUtils.IS_OS_WINDOWS_2000
SystemUtils.IS_OS_SOLARIS
SystemUtils.IS_OS_MAC_OSX
Is there a way to detect the platform (Window / Linux) in which the website is running by Groovy / Grails?
System.properties['os.name']
will return the name of the OS, e.g. "Windows XP". So if you want to figure out whether you're running on Windows or not, you could do something like:
if (System.properties['os.name'].toLowerCase().contains('windows')) {
println "it's Windows"
} else {
println "it's not Windows"
}
Alternatively, org.apache.commons.lang.SystemUtils
(from the Apache commons-lang project) exposes some boolean 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
这篇关于通过groovy / grails检测平台(Window或Linux)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!