stdin redirect works, pipe fails

1. redirect stdin/out to unnamed pipe

Using C, I need to redirect the stdin and stdout of a child process
(made by fork'ing and then execve'ing) to unnamed pipes created by

I know freopen would allow me to redirect them to named pipes or
files, but I really need to use unnamed pipes for this.  I've found a
solution, but I'm not really sure it's the correct one, and might not
be robust.  Below is what I'm doing now (this is just a snippet, of
course).  Basically, I create my pipes, associate FILE structs with
them to make them real streams like stdin and stdout, and then copy my
structs into the structs for the stdin and stdout streams.  It seems
to work, but....

Thank you for your time.  Replies may be posted to the group or sent
to me personally via email.

Randall Nortman
The University of Chicago

int stdin_pipe[2], stdout_pipe[2];
FILE *stdin_stream;
FILE *stdout_stream;

/* Open 2 pipes */

/* Associate read end of one pipe with stdin_stream */
stdin_stream = fdopen(stdin_pipe[0], "r");

/* Associate write end of other pipe with stdout_stream */
stdout_stream = fdopen(stdout_pipe[1], "w");

/* Now copy the FILE structs for our streams to the FILE structs for
   stdin and stdout */
bcopy(stdin_stream, stdin, sizeof(FILE));
bcopy(stdout_stream, stdout, sizeof(FILE));

/* Now reads from stdin and writes to stdout should access our pipes, so
   we can execve the new process */


2. Slow direct downloads from T-DSL, fast via Masquerading/LAN

3. redirecting stdin to the second command of a pipe

4. printing from behind a masq

5. How do I redirect stdin from a pipe to frecover?

6. Reading BSD partition from Linux/Intel


8. Help on compiling kernel 1.3.72

9. Port Redirect works but doesn't redirect internal traffic

10. redirecting stdin with yppasswd

11. piped data & 'read' stdin

12. Redirecting to STDIN

13. to pipe the stderr to stdin