Sending some input into a process, then resuming input from command line

command lineinputterminal

I have an interactive terminal program, that accepts stdin (telnet for example).

I want to send it some input before interacting with it, like this:

echo "Hello" | telnet somewhere 123

But that only sends in Hello and kills telnet afterwards. How can I keep telnet alive and route input to it?

Best Answer

You can't change what STDIN of telnet is bound to after you start, but you can replace the simple echo with something that will perform more than one action - and let the second action be "copy user input to the target":

{ echo "hello"; cat; } | telnet somewhere 123

You can, naturally, replace cat with anything that will copy from the user and send to telnet.

Keep in mind that this will still be different to just typing into the process. You have attached a pipe to STDIN, rather than a TTY/PTY, so telnet will, for example, be unable to hide a password you type in.

Related Question