Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

read list of installed softwares in linux using java program

 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to write a java program which runs on a linux machine,and this java program should give the list of installed rpms on that machine. I am not sure what is to be done. I also gone through the site which tells how to "http://www.codeproject.com/KB/files/CoolCode.aspx" read the list of sofware's installed on windows. I want something similar for my linux machine.

Any information on this would be great...
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would be hard to do that in Java, because RPM's are not merely OS-specific, they're specific to only certain Linux distros. Debian and Ubuntu, for example, use ".deb" packages, instead.

However, it's a trivial task to get the list of installed RPM's. In many releases, it's kept in /var/log/rpmpkgs, although interestingly, I see that Fedora 14 isn't one of them.

For systems where that file isn't available, you can simply query RPM itself with the "rpm -qa" command and read the stdout stream. If the basic package name isn't sufficient and you want refinements like the actual release, there are additional options. This is the one that builds /var/log/rpmpkgs:


The actual cron job sorts the results using the "sort" utility.
 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim,

So i believe what i should do is run something like this below?



Please correct me if iam wrong
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't really see the purpose of using Java for doing this, since after all you end up just execing a process from Java. What's the requirement for using Java?
 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this java program runs on a linux machine.It reads all the rpms installed on that linux machine and displays to the user..hope you got it now..
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the key:
Maan Suraj wrote:displays to the user

And you never said what kind of display!
If displaying on the command line, then writing a Java app is useless - use Tim's one-liner instead.
If displaying in a web browser or in a GUI, then Java will be helpful in formatting the display, though you would still use Tim's one-liner to gather the data.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11877
195
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depending on usage, I would probably recommend using WebMin.
 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone
@Peter: Yes it is to display in thr browser.

Ya Tim's one liner helped. Also below code works fine



thanks :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic