Needed to get stderr with popen:
* Purpose: Program to demonstrate the popen function.
* to do: Check that the ‘popen’ was successfull.
* Author: M J Leslie.
* Date: 08-Jan-94
char line; /* line of data from unix command*/
fp = popen(“ls -l”, “r”); /* Issue the command. */
/* Read a line */
while ( fgets( line, sizeof line, fp))
– popen will always execute the command from within the Bourne shell. – popen feeds the STDOUT back to your program. If you want STDERR, the following will do the trick.
fp=popen(“ls -l 2>&1”, “w”);