There is an interesting option in Ipython Jupyter Notebook to execute command line statements directly from the notebook. For example:
! mkdir ...
! python f
I'm posting this as an answer. It's not a good answer, but the way I'd handle the problem is to write a bash script to be run in the background. I've looked into the '!' operator and it doesn't seem to have a lot of documentation. I can't even find it in the Jupyter source. This article:
[Safari book about Jupyter Predecessor and component IPython][1]https://www.safaribooksonline.com/blog/2014/02/12/using-shell-commands-effectively-ipython/
suggests that this is simply the way things were before and probably forever shall be. Unless you want to hack into the Magic Commands part of the Jupyter Notebook and fix it yourself.
That said, given that with a little bash programming (It's simple and focused) you can do what you're trying to do, you might consider that route. Especially if you need results enough to put reputation on it.
If you want to look into running bash scripts with against an expected response this answer is what you're looking for: Have bash script answer interactive prompts