Skip to main content
Source Link
Jason R
  • 657
  • 1
  • 6
  • 12

Piping data to a process's stdin without causing EOF afterward

I have an executable that starts a user-interactive shell. I would like to, upon launch of the shell, inject a few commands first, then allow the user to have their interactive session. I can do this easily using echo:

echo "command 1\ncommand 2\ncommand3" | ./shell_executable 

This almost works. The problem is that the echo command that is feeding the process's stdin hits EOF once it's done echoing my commands. This EOF causes the shell to terminate immediately (as if you'd pressed Ctrl+D in the shell).

Is there a way to inject these commands into stdin without causing an EOF afterwards?