简体   繁体   中英

Supervise a Python subshell

I want to run a Python Interpreter as an inferior process in bash or zsh . During this time, I would like to send commands to the process and see the output in STDOUT . Something like this:

$ in=/dev/shm/python_test_in
$ out=/dev/shm/python_test_out
$ touch $in $out
$ python < $in > $out
$ echo print(1+1) > $in
$ cat $out

Sadly, this does not work. I am running GNU/Linux.

What you need is a pipe:

mkfifo ./in ./out
python < ./in > ./out &
echo "print(1+1)" > ./in
cat ./out

However, in this way, the python interpreter will quit immediately after this execution because it read an EOF in the "echo" line. I'm looking for the way to prevent the python interpreter from exiting on EOF.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM