Saturday, August 1, 2020

How to detect OS in kotlin

In kotlin also you can use System.getProperty("os.name") for detect type OS.

Check example class test.kt

fun main(args: Array<String>) {

val OS = System.getProperty("os.name").toLowerCase()

when {
OS.indexOf("win") >= 0 -> {
print("Windows")
}
OS.indexOf("mac") >= 0 -> {
print("Mac")
}
(OS.indexOf("nix") >= 0
|| OS.indexOf("nux") >= 0
|| OS.indexOf("aix") > 0) -> {
print("Unix or Linux")
}
OS.indexOf("sunos") >= 0 -> {
print("Solaris")
}
else -> print("Others")
}


}






References:
http://lopica.sourceforge.net/os.html
https://mkyong.com/java/how-to-detect-os-in-java-systemgetpropertyosname

No comments:

Post a Comment

Provisioning Cloud SQL with Private Service Connect Using Terraform & Accessing from Cloud Run with Spring Boot

In this post, we'll explore how to provision Cloud SQL instances with Private Service Connect (PSC) connectivity using Terraform and the...