Is it possible to programmatically enter some repl (say mongo), and programmatically interact with it? That is to say, can you do this programmatically:
$ mongo
MongoDB shell version: 2.4.8
connecting to: test
> db.collections
test.collections
> exit
bye
All that does is:
- Login to the REPL with the
mongocommand. I know it's possible to do this somehow, I have seen it done to create interactive REPL's in the Node.js world. It would be helpful to know how to do this in bash directly. - Once logged in, I typed
db.collections, just exploring the REPL. This SO question is asking, can you do this programmatically? Like can you perhaps (a) create a child process/REPL from a bash script, and then (b) send it arbitrary messages like thisdb.collections, which it evaluates. (And can you get the response/output back). - Programmatically log out of the REPL.
Is this possible?
<< EOS .... cmds ... EOS(Unfotunately,EOScan be any arbitrary string, so sometimes you see<< _or<< EOD, or << ...` (a dozen other things.). Focus on "Here-Documents" and do small tests to see ifmongocan read from them. Else look atexpect. Good luck.stdin), go forexpectbased solution.