I’m developing a program which executes a program using execvp. It needs to capture the results of the child process and parse them in the main process. It seems there is a way, using named pipes, and duping. I’m trying to hunt down a good example of this, but so far no luck. If anyone has any pointers, links and/or suggestions about this, I’d greatly appreciate it.
I’m developing a program which executes a program using execvp. It needs to capture
Share
You don’t need named pipes; unnamed pipes work just fine. Actually, often you can just use
popeninstead of doing thepipe/fork/dup/execyourself.popenworks like this (though yourlibc‘s implementation likely has more error checking):This creates an unnamed pipe, and
forks. In the child, it reattaches stdout (or stdin) to one end of the pipe, thenexecs the child. The parent can simply read (or write) from the other end of the pipe.