1

Possible Duplicate:
Best way to capture stdout from a system() command so it can be passed to another function

In linux to get the current status of a service I wrote this code segment::

   char cmd[100];
   sprintf(cmd,"service %s status",argv[1]);
   system(cmd);

It is running fine and it shows the output on the console like : mysql is running OR mysql is stopped

But I need this console output in a string variable. How can I get 'mysql is running' in a string variable so that I can use this string variable later. thankx.

Community
  • 1
  • 1
Ronin
  • 2,027
  • 8
  • 32
  • 39

1 Answers1

1

If you want to capture output then use popen() rather than system().

Paul R
  • 208,748
  • 37
  • 389
  • 560