File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Linux / UNIX and the fly likes read list of installed softwares in linux using java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "read list of installed softwares in linux using java program" Watch "read list of installed softwares in linux using java program" New topic
Author

read list of installed softwares in linux using java program

Maan Suraj
Ranch Hand

Joined: Dec 20, 2007
Posts: 299
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...


Man Suraj
Someone says "Impossible is nothing". The man next him says "Let me see you licking your elbow tip!"
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16012
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Maan Suraj
Ranch Hand

Joined: Dec 20, 2007
Posts: 299
Thanks Tim,

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



Please correct me if iam wrong
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10046
    
163

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?

[My Blog] [JavaRanch Journal]
Maan Suraj
Ranch Hand

Joined: Dec 20, 2007
Posts: 299
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

Joined: May 14, 2008
Posts: 5823
    
    7

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.

JBoss In Action
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11423
    
  85

Depending on usage, I would probably recommend using WebMin.


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Maan Suraj
Ranch Hand

Joined: Dec 20, 2007
Posts: 299
Thanks everyone
@Peter: Yes it is to display in thr browser.

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



thanks :-)
 
Consider Paul's rocket mass heater.
 
subject: read list of installed softwares in linux using java program