LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-30-2008, 06:15 PM   #1
tara
Member
 
Registered: Aug 2005
Location: Australia
Distribution: Centos 7
Posts: 58

Rep: Reputation: 15
rpm -qa within a c program


Hi

I have a C program that has the following line

Code:
  
  if (system("rpm -qa | grep rpm_name > /tmp/version.txt") == 0)
  { //do stuff
  }
  else
  { //do something else 
  }

What i want to be able to do is test if a certain rpm is installed on the machine by writing the result of the above to version.txt.

What i am finding is that the rpm is being written to the version.txt file but it does not do into the if but into the else when it should be going into the if.

Have a got the wrong return value??

thanks
Tara


edit: sorry just released that this should probably go in programming?

Last edited by tara; 06-30-2008 at 06:21 PM.
 
Old 06-30-2008, 07:41 PM   #2
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Shouldn't this be posted under Programming?
 
Old 07-01-2008, 09:53 AM   #3
cconstantine
Member
 
Registered: Dec 2005
Distribution: RedHat, Ubuntu
Posts: 101

Rep: Reputation: 15
command failing?

perhaps you need to specify the full path to 'rpm'?

Depending on your current working dir at runtime, and the evironment (or lack there of) containing a search path... "rpm" may work for you in a shell, but not in the system() environment...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
uninstall program without rpm wincrk Linux - Newbie 2 05-11-2006 04:52 AM
Removing rpm program leonidg Linux - Software 2 12-26-2004 01:25 AM
i make a program using forte how can i generate from that program an rpm abdelhlims Programming 0 07-13-2004 12:10 PM
Broke my RPM program vincebs Red Hat 4 12-29-2003 01:46 AM
Installing an .rpm program Tynoan Slackware 4 06-05-2003 02:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration