shell - Programmatically send commands to an interactive REPL from Bash? -


is possible programmatically enter repl (say mongo), , programmatically interact it? say, can programmatically:

$ mongo mongodb shell version: 2.4.8 connecting to: test > db.collections test.collections > exit bye 

all is:

  1. login repl mongo command. know it's possible somehow, have seen done create interactive repl's in node.js world. helpful know how in bash directly.
  2. once logged in, typed db.collections, exploring repl. question asking, can this programmatically? can perhaps (a) create child process/repl bash script, , (b) send arbitrary messages db.collections, evaluates. (and can response/output back).
  3. programmatically log out of repl.

is possible?

you write expect script interactively input commands you. i'm not regular expect user think should this:

#!/usr/bin/expect mongo set timeout 10 expect "mongodb shell version: 2.4.8" send "db.collections" expect "test.collections" send exit 

there lot of examples out there should make easy create minimal working example.