linuxunixpipe

How can I pipe initial input into process which will then be interactive?


I'd like to be able to inject an initial command into the launching of an interactive process, so that I can do something like this:

echo "initial command" | INSERT_MAGIC_HERE some_tool

tool> initial command 

[result of initial command] 

tool> [now I type an interactive command]

What doesn't work:

What would but with disadvantages:

(The tool of current interest, incidentally, is android's adb shell - I want to open an interactive shell on the phone, run a command automatically, and then have an interactive session)


Solution

  • You don't need to write a new tool to forward stdin - one has already been written (cat):

    (echo "initial command" && cat) | some_tool
    

    This does have the downside of connecting a pipe to some_tool, not a terminal.