LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   rpm -qa within a c program (https://www.linuxquestions.org/questions/linux-software-2/rpm-qa-within-a-c-program-652674/)

tara 06-30-2008 06:15 PM

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?

stress_junkie 06-30-2008 07:41 PM

Shouldn't this be posted under Programming?

cconstantine 07-01-2008 09:53 AM

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


All times are GMT -5. The time now is 04:58 AM.