Capaz de testar com código abaixo usando perl para evitar o buffer, tente se isso funciona para você
Sample version of P
$ cat /tmp/P
#!/bin/bash
read input
if [[ $input = "Hello" ]]
then
echo "Why?"
else
exit 1
fi
echo "Got Hello from client, working ..."
sleep 10
echo "Need to read some input"
read x
echo "Got: $x"
The wrapper program
$ cat /tmp/wrapper
#!/usr/bin/zsh
coproc /tmp/P
print -p Hello # Send Hello to P
read -pr line # Read what P has to say
if [[ "$line" = "Why?" ]]; then
perl -e '$|=1;print $_ while(<>);' <& p &
perl -e '$|=1;print $_ while(<>);' >& p
else
echo "Could not get P's attention."
fi
Test run
$ /tmp/wrapper Got Hello from client, working ... Need to read some input hi there P! <== Typed in at teminal Got: hi there P!