Pipe to executable without exiting/EOF in bash

bash, sh

Solution

You can use expect to automate that. For example:

#!/usr/bin/expect

spawn /my/exec
expect "> "
send "input1\r"
interact

Problem

I have a (read-only) executable "myexec" which I always execute followed by the input "input1" (a string), and then I get on with my business "" and "exit" when I feel like it: ``` $ myexec > input1 > do something else for as long as I like > exit ``` What I would like to do is automatically execute "myexec" with the input "input1", and then be able to "do something else for as long as I like". From what I can see, my options are: ``` $ myexec <<< "input1" ``` or ``` $ echo "input1" | myexec ``` or ``` $ myexec << EOF input1 EOF ``` BUT the problem with these methods is that they terminate "myexec" after reading "input1". How can I avoid the EOF/exit/terminate?

Original source