I have a program
P that expects to receive "Hello" and output "Why?" before providing a feature. This feature is used by other programs that are not aware that it is common courtesy to start a conversation with "Hello". I thus want to write a wrapper for
P that works like this (zsh syntax):
coproc P print -p Hello # Send Hello to P read -pr line # Read what P has to say [[ "$line" = "Why?" ]] && Replace current process with the coprocess. echo Could not get P's attention.
dd in the
Replace... part (something like
cat <&p &; exec cat >&p) results in unnecessary buffering. What are my options?