/* * Run the 'ls' command and print the output to stdout. * * Compile with * gcc -Wall pipe.c -o pipe * * * Mithenks * */ #include #include 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; }