• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to get linux distributions name in java?  RSS feed

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
how can i get linux distributions name in java ??? i try it by Syatem.getProperty("os.name") but this return only "Linux" !!!
is any way to return like fedora , suse , ... ???
thanks
 
Ranch Hand
Posts: 152
Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

os.name basically gives you the same as the UNIX command "uname" when invoked with no parameters.

For Red Hat and family you could read the file /etc/redhat-release.

It will give you something like:

  • Red Hat Enterprise Linux Server release 5.4 (Tikanga)
  • CentOS release 5.4 (Final)
  • Fedora release 12 (Constantine)


  • Hope that helps.
    Matt
     
    mahdi farzami
    Ranch Hand
    Posts: 32
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    thanks my frieand
    it`s seem`s this file is diffrent in other distribiutions , is any other common file
    thanks
     
    Sheriff
    Posts: 21135
    87
    Chrome Eclipse IDE Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You can try using ProcessBuilder* to execute "uname -a". In which case you must read this article.

    * I prefer it over Runtime.exec() since it has just a bit more features (error to output redirecting being the most important one).
     
    Matt Cartwright
    Ranch Hand
    Posts: 152
    Linux VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Rob Prime wrote:You can try using ProcessBuilder* to execute "uname -a".


    uname isn't able to tell what Linux distro the host is running.

    and as with /etc/redhat-release, the output for Red Hat Enterprise Linux and
    Oracle Enterprise Linux (Unbreakable Linux) will be exactly the same.

    If you then run it on Nexenta (some say it is Linux because of its Debian packages)
    you get some funny stuff like "SunOS" at the beginning and "Solaris" at the end.

    On Nexenta as well as OpenSolaris the user's uname is /usr/gnu/bin/uname.
    On Intel and Sparc Solaris it is /sbin/uname and not even on your path.

    Regarding architecture, who do you believe?



    CentOS 5.4

    matt@talon:~$ java OSInfo
    OS name : Linux
    OS version : 2.6.18-164.11.1.el5
    OS architecture : i386
    matt@talon:~$ uname -m
    i686


    Fedora 12

    matt@maverick:~$ java OSInfo
    OS name : Linux
    OS version : 2.6.32.9-70.fc12.x86_64
    OS architecture : amd64
    matt@maverick:~$ uname -m
    x86_64


    Intel Solaris

    matt@sidewinder:~$ java OSInfo
    OS name : SunOS
    OS version : 5.11
    OS architecture : x86
    matt@sidewinder:~$ /sbin/uname -m
    i86pc


    From my point of view, if you wanna make system calls, don't use a system exit.
    Write your program in C and rely on POSIX standards.

    just an opinion
    Matt
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!