In your code you are closing pipe[0]
which is not the descriptor you are writing to the child. You did a dup2(pipes[1], 1)
so in order to tell the child that the pipe has ended you must close the one you are writing to.
close(1);
Of course you'd have to restore the original output if you intend to continue your process using stdout, as this would be closed now.