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.

0

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.