I need to write a C program (myprogram
) which checks output of other programs. It should basically work like this:
./otherprogram | ./myprogram
But I could not find how to read line-by-line from stdout
(or the pipe), and then write all this to stdout
.
One program's stdout
becomes the next program's stdin
. Just read from stdin
and you will be fine.
The shell, when it runs myprogram
, will connect everything for you.
BTW, here is the bash code responsible: http://git.savannah.gnu.org/cgit/bash.git/tree/execute_cmd.c
Look for execute_pipeline
. No, the code is not easy to follow, but it fully explains it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With