simple string comparison problem

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int main ()
{
  string i;

  i=system("ps -A | grep firefox | awk '{print $4}'");
  cout << i << endl;

  if ( i == "firefox" )
  {
    cout <<"Firefox is running"<< endl;
  }
 else
  {
    cout <<"Firefox is not running" << endl;
  }

 return 0;

}



Why does this result in "Firefox is not running" even though it is?

Thank you for any replies :-)
What is "i" at that time exactly? strings are case sensitive so "Firefox" != "firefox"
Man, implicit int to char coersion sucks.

Hint: you want popen(3), not system(3).

Topic archived. No new replies allowed.