This seemed like something pretty obvious, but after a lot of searching, was not able to find the right search terms to get the answer. Searches for things like "connect to python kernel" brought up only pages and pages of stuff about Jupyter and IPython.
Bash
I found this which has something close using a coprocess.
My ideal thing would be:
create_named_process proc1
create_named_process proc2
Then someohow send a command to proc1 and get the output and send a command to proc2 and get the output. Then do it over again with more commands.
Python
I did find Python subprocess
and bash subshells. But not sure how to keep those going in the background and connect to them. For instance, I could do
process = subprocess.Popen(['your_background_command'])
stdoutdata, stderrdata = process.communicate()
But I think if I kill the process I started the subprocess in, then the subprocess will die. (A commenter said that using Shell=True
will cause the process to stay alive, but not sure how I would then access it. They removed the comment).
Also, how can I pass more commands to the process? Nothing like that in the documentation.
Note this post contains edits.