There are two scripts, the first in the background, the second in the foreground:
trap "ret=\$?; rm -f pipe1 pipe2; exit \$ret" EXIT INT TERM QUIT
my.bin > pipe1 < pipe2 &
my-term.sh pipe1 pipe2
my-term.sh interacts with the user via stdin/stdout (it's like a CLI terminal program):
while read -ep "prompt> " l; do echo $l; done
my.bin can be simulated with just exit 0 script.
How to terminate my-term.sh if my.bin exits for any reason?
What works:
trap "ret=\$?; rm -f pipe1 pipe2; exit \$ret" EXIT INT TERM QUIT
(my.bin > pipe1 < pipe2; kill -9 $$) &
my-term.sh pipe1 pipe2
But it probably stops my-term.sh from cleanups. How to do it correctly?