|Think about Loose Coupling|
The tough part about doing this is dealing with buffering.
Assume the conversation goes: Supply input -> get output -> supply input dependant on last output -> get output ...
If the first set of output is insufficient in quantity to cause all the buffers (the program's output buffer and the pipe buffer) to be flushed, you end up in a position where the driven program is waiting for new input, and the driving script is still waiting for the last set of output.
The former won't produce any more output until it gets more input; and the latter won't supply any more input until it has seen the last output. Result: deadlock.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.