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
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Reply 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: 285
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: 12513

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.


One of the most odious afflictions that Business has inflicted on the modern English language is "pro-active". Most of the time it's simply redundantly used in place of the simple old word "active". And a good deal of the rest of the time it means "You're not overworked enough yet, so go out and find more!"
Maan Suraj
Ranch Hand

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

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



Please correct me if iam wrong
Jaikiran Pai
Saloon Keeper

Joined: Jul 20, 2005
Posts: 6720

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: 285
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: 4875

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: 9982

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: 285
Thanks everyone
@Peter: Yes it is to display in thr browser.

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



thanks :-)
 
 
subject: read list of installed softwares in linux using java program
 
Threads others viewed
windows registry reading
logging into linux machine through java
Reading Windows Registry Content through Java
Eclipse Installer!
Parallel and Serial Comm Using Java Comm API on Linux OS System
MyEclipse, The Clear Choice