Capturing Input/Output of Another Process in C
In my travels in C programming, I periodically need to run another process and redirect its standard output back to the first process. While it is straight forward to perform, it is not always obvious. This article will explain the process of how this is done in three sections.
- High Level Overview
- Explanation of each line
- Code Sample
High Level Overview
Create a three pipe(2)s for standard input, output and error fork(2) the process The child process runs dup2(2) to over the pipes to redirect the new processes’s standard input, output and error to the pipe. The parent process reads from the pipe(2) descriptors as needed.
Read more...