简体   繁体   English

监督Python子外壳

[英]Supervise a Python subshell

I want to run a Python Interpreter as an inferior process in bash or zsh . 我想在bashzsh中将Python解释器作为劣等程序运行。 During this time, I would like to send commands to the process and see the output in STDOUT . 在这段时间内,我想向该进程发送命令,并在STDOUT查看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. 我正在运行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. 但是,以这种方式,python解释器将在执行后立即退出,因为它读取了“ echo”行中的EOF。 I'm looking for the way to prevent the python interpreter from exiting on EOF. 我正在寻找防止EOF退出python解释器的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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