I have to write program which reads a correct linux pipe for example:
program1 | program2 | program3 | program 4
and proceeds with pipes.
I'm doing something like this:
then i'm getting first command (i'm looking for the first '|'). Then I'm forking function with a string without begining (in the example above, im forking with string "program2 | program3 | program 4" and then in the parent i'm executing "program 1" with popen(). Then i'm reading the data from this pipe (what program1 returns) and then seding it to the child. Child recieves it. And here is my problem. Child has to run "program2" with everything what program1 sent. But I don't really know how to do this. I'm doing something like this: I have a string in which I have a "program2" + data which child received from parent and run it with popen(). But it doesn't seem to work like with an example:
cat file | grep something.
Is there any universal way to running programX with the data recieved from the parent?