int main()
{
char buf[5];
int fd_in[2], fd_out[2],
c;
pipe(fd_in);pipe(fd_out);
if(fork() == 0)
{
close(fd_in[WRITE]);dup2(fd_in[READ], READ);
close(fd_out[READ]); dup2(fd_out[WRITE], WRITE);
dup2(fd_out[WRITE], WRITE); //stdout -> pipe's write (everything what would go to stdout will go to the pipe's write...
execlp("sort", "sort", NULL);
}
I forgot a lot of C and POSIX.
But I noticed you don't have a parent process branch for the fork().
On a minor note, you don't do perror() checking, which would help you.
As far as your post is concerned, please use [code]int a=5; // code [/code] tags when copy-pasting code.
Must you use a pipe to get the stdin input?
Because if not you could use fread(a, b, c, stdin); for the input.
Then you use two pipes and dup2(), like you tried.
And finally fwrite(a, b, c, stdout);.
If you need to use write() and read() just remember that 0 = stdin and 1 = stdout.
Just taking a quick glance at your code, you're doing dup2 on the child's stdout twice, I don't know what the effect of this is, but I don't think it's right. Also, you haven't closed either end of either pipe in the parent.