aspose file tools
The moose likes Java in General and the fly likes how to get linux distributions name in java? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "how to get linux distributions name in java?" Watch "how to get linux distributions name in java?" New topic
Author

how to get linux distributions name in java?

mahdi farzami
Ranch Hand

Joined: Nov 21, 2009
Posts: 32
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
Matt Cartwright
Ranch Hand

Joined: Aug 25, 2008
Posts: 149


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

    Joined: Nov 21, 2009
    Posts: 32
    thanks my frieand
    it`s seem`s this file is diffrent in other distribiutions , is any other common file
    thanks
    Rob Spoor
    Sheriff

    Joined: Oct 27, 2005
    Posts: 19216

    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).


    SCJP 1.4 - SCJP 6 - SCWCD 5
    How To Ask Questions How To Answer Questions
    Matt Cartwright
    Ranch Hand

    Joined: Aug 25, 2008
    Posts: 149

    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
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: how to get linux distributions name in java?
     
    Similar Threads
    Survey- What platform do you use to program in Java?
    java uninstallation in linux
    linux or redhat? and some questions
    Linux - SUSE or Ubuntu?
    Eclipse on Linux?????