Вы хотите функцию popen ". Ниже приведен пример запуска команды ls /etc
и вывода на консоль.
#include#include int main( int argc, char *argv[] ) { FILE *fp; int status; char path[1035]; /* Open the command for reading. */ fp = popen("/bin/ls /etc/", "r"); if (fp == NULL) { printf("Failed to run command\n" ); exit; } /* Read the output a line at a time - output it. */ while (fgets(path, sizeof(path), fp) != NULL) { printf("%s", path); } /* close */ pclose(fp); return 0; }