#include #include #include int main(void) { int pip[2]; pipe(pip); if(!fork()) { // make pip[1] a stdout dup2(pip[1], 1); close(pip[1]); // close the unneeded fd close(pip[0]); // close unneeded fd (reading part of pipe) execl("/bin/sh", "sh", "-c", "echo x", NULL); _exit(-1); } close(pip[1]); // close unneeded fd (writing part of pipe) FILE*fp = fdopen(pip[0], "rt"); char Buf[512]; fgets(Buf,sizeof Buf,fp); fclose(fp); printf("Got %s\n", Buf); while(wait() > 0); return 0; }