I'm writing a bash script that fires up python and then enters some simple commands before exiting. I've got it firing up python ok, but how do I make the script simulate keyboard input in the python shell, as though a person were doing it?
Use a "here" document. It looks like this
command << HERE
text that someone types in
more text
HERE
You don'th have to use "HERE", you can use something that has a little more meaning relative to the context of your code.
If you really need to simulate typing into the Python interpreter, rather than piping a command to python, you can probably do this with expect
expect should be available in your distribution's repository. For details,
man expect
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With