popen() – execute shell command from C/C++
Copied from http://www.sw-at.com/blog/2011/03/23/popen-execute-shell-command-from-cc/March 23rd, 2011 by Atul Sharma
The popen() function executes a command and pipes the executes command to the calling program, returning a pointer to the stream which can be used by calling program to read/write to the pipe.
Below are the C/C++ snippets to run a simple command, read the stream from pipe and then write to console.
C Implementation
C++ Implementation
Below are the C/C++ snippets to run a simple command, read the stream from pipe and then write to console.
C Implementation