Search code examples
shellhttp-redirectcommand-linestdinfile-descriptor

How to inject something to stdin of another process


Is it possible to start an interactive shell program and inject something to its stdin, keep it running afterwards, and that in a single line?

I'd like to start electron -i (REPL mode) and execute .load index.js right away. It has no switch that accepts code to execute unlike many other REPLs.

echo ".load index.js" | electron -i

will execute but terminate immediately.

Could juggling with filedescriptors somehow achieve this?

Interesting resources


Solution

  • Yes, with expect, like this:

    expect -c 'spawn electron -i; send .load index.js\r; interact'