I think it depends on which version of NDK you are using.
Also, looking at the gingerbread sources tree for bionic, I found a popen implementation. The implementation may not be 100% posix libc correct, but it is at least functional to some extent.
Using NDK v6, the following example compiles without any problems and it runs on my Android device.
#include <stdio.h> #include <stdlib.h> int main() { FILE *fpipe; char *command="/system/bin/ps"; char line[256]; if ( !(fpipe = (FILE*)popen(command,"r")) ) exit(1) while ( fgets( line, sizeof line, fpipe)) { puts(line); } pclose(fpipe); }
UPDATE: It seems that instead of previous versions of ICS, vfork () is used instead of fork (), and it is known that vfork () causes stack corruption.
So, from ICS, onward popen should be kept in use, but on earlier versions of Android it is available, but verry buggy.
source share