(Help) How to take output of linux shell command in C/C++ program

Help: How to take output of linux shell command in C/C++ program

How to take output of following command/ or any linux shell script in c/c++ program

Question:
This command return the system memory/ram size.

char *szCommand="grep MemTotal /proc/meminfo";
system(szCommand);

Is there any alternative of doing this?

Answer:
If I understand your question correctly, you wish to examine with your program the output of an executed program or script or shell command line.

Do this at the command line:
Code:

man popen

If man pages are not installed on your system, google this:
Code:

linux man popen

Hope this helps.

Courtesy:- http://www.linuxforums.org

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Google