Link to home
Start Free TrialLog in
Avatar of dshrenik
dshrenikFlag for United States of America

asked on

Identify Operating System

Please let me know how I can figure out the Operating system (windows or mac) through java code.

Thanks!
Avatar of for_yan
for_yan
Flag of United States of America image

System.getProperty("os.name")
Avatar of dshrenik

ASKER

Is it possible to identify the family of OS?
I want to know if it windows / mac / linux. But I don't care which version.

String s = System.getProperty("os.name")
if(s.startsWith("Windows")) - this is windows,
but you should run some tests whaat weach system returns
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
But is there a generic way to figure out the family.
Like in ant, I can do this:

  <condition property="avn" value="avn.bat">
    <os family="windows"/>
  </condition>
I am not sure there is a generic way - and how could it be - someone can come up with some new system
which will do something new

the tests in http://www.mkyong.com/java/how-to-detect-os-in-java-systemgetpropertyosname/
should cover most of the cases, but not guaranteed of faling