Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Bash脚本与IPython内核交互_Ipython - Fatal编程技术网

从Bash脚本与IPython内核交互

从Bash脚本与IPython内核交互,ipython,Ipython,是否可以与IPython交互会话或Bash脚本中的内核交互?理想情况下,我希望这样做,在shell脚本中,我知道send子命令可能不存在这样的情况: # do stuff in Bash ... # start a kernel and get its Id KERNEL=`ipython init --command="print(__KERNELID__)"` # do something inside the kernel ipython send --kernel=KERNELID --

是否可以与IPython交互会话或Bash脚本中的内核交互?理想情况下,我希望这样做,在shell脚本中,我知道send子命令可能不存在这样的情况:

# do stuff in Bash ...
# start a kernel and get its Id
KERNEL=`ipython init --command="print(__KERNELID__)"`
# do something inside the kernel
ipython send --kernel=KERNELID --command="mylist = [0,1,2]"
然后,理想情况下,命令

ipython send --kernel=KERNELID --command="print(mylist)"
将输出

[0, 1, 2]
最后,我需要以某种方式销毁内核:

ipython-kernel=KERNELID-command=sys.exit

可能已经有了一个机制来做我想做的事,
正当不幸的是,我没能找到它…

有很多方法可以解决这个问题。既然您必须使用python,那么您也可以使用python来完成整个工作。Python程序可以接受像mylist这样的命令行参数,并对它们执行任何操作

由于您正在发送要评估的命令,请确保您是控制输入的人。不要让别人开始输入导入操作系统和操作系统。例如,取消[此处的硬盘]链接

其他选项:查看expect For your interactive needs
或者只是python版本查看pexpect模块

谢谢您的回答!事情已经结束了Bash脚本的过程,我需要反复访问相同的Python会话。这意味着,在bash脚本中的某一时刻,我需要向Python会话提供一些信息,而在稍后的阶段,我需要从该Python会话中检索信息。