A simple example of using pipe in Linux. Regards -- Homepage: http://www.mithenks.com Slackware GNU/Linux User since 2003 Registered Linux User #383379 Registered Linux Machine #391361
/* * Run the 'ls' command and print the output to stdout. * * Compile with * gcc -Wall pipe.c -o pipe * * * Mithenks <mithenks@xxxxxxxxxxxxxx> * */ #include <stdio.h> #include <stdlib.h> int main() { FILE *pipe; char buffer[1024]; if ( (pipe = popen("ls","r") ) < 0 ) { perror("popen(): "); exit(-1); } fread(buffer,sizeof(buffer),1,pipe); printf("Output:\n%s\n",buffer); pclose(pipe); return 0; }