Identify Operating System

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

Thanks!
dshrenikAsked:
Who is Participating?
 
for_yanCommented:
you can look here ofr example of dioing something like that
http://www.mkyong.com/java/how-to-detect-os-in-java-systemgetpropertyosname/
0
 
for_yanCommented:
System.getProperty("os.name")
0
 
dshrenikAuthor Commented:
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.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
for_yanCommented:

String s = System.getProperty("os.name")
if(s.startsWith("Windows")) - this is windows,
but you should run some tests whaat weach system returns
0
 
dshrenikAuthor Commented:
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>
0
 
for_yanCommented:
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
0
 
dshrenikAuthor Commented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.