You want popen()
. Here's an example, taken from... (see below).
void get_popen_data() { FILE *pf; char command[COMMAND_LEN]; char data[DATA_SIZE]; // Execute a process listing sprintf(command, "ps aux wwwf"); // Setup our pipe for reading and execute our command. pf = popen(command,"r"); if(!pf){ fprintf(stderr, "Could not open pipe for output.\n"); return; } // Grab data from process execution fgets(data, DATA_SIZE , pf); // Print grabbed data to the screen. fprintf(stdout, "-%s-\n",data); if (pclose(pf) != 0) fprintf(stderr," Error: Failed to close command stream \n"); return;}
Edit: I have removed the link to the original source code as it looks like a domain change has occurred and the site now contains some nasty looking malware.