Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get operating system in Java

I know there is such a question on SO, but I could not find it. So asking again...

I need to set up properties to my program, but I need to make it OS indipendent - running both on Windows XP and Linux (unknown distro, unknown version)

More specifically - I need to set up to the system where to find the chromedriver binary. I need something like this pseudocode:

 if (getOs() == Windows){
    System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "chromedriver.exe");
   } else{
     System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, "chromedriver");
   }

Now I need the part for getting the OS. Thanks for help.

like image 610
Pavel Janicek Avatar asked Nov 30 '22 02:11

Pavel Janicek


1 Answers

System.getProperty("os.name");
System.getProperty("os.version");
System.getProperty("os.arch");
like image 148
Henrique Miranda Avatar answered Dec 04 '22 15:12

Henrique Miranda