Communication between two gnome-terminal sessions

泄露秘密 提交于 2019-12-02 10:35:39

You could change your handler to read from a file given at the command line instead of stdin:

#!/usr/bin/env python
import shutil
import sys
import time

print "In handler..."
with open(sys.argv[1], 'rb') as file:
    shutil.copyfileobj(file, sys.stdout)
sys.stdout.flush()
time.sleep(5)

Then you could create a named pipe in main.py, to send the data:

#!/usr/bin/env python
import os
from subprocess import Popen

fifo = "fifo"
os.mkfifo(fifo)
p = Popen(["gnome-terminal", "-x", "python", "handler.py", fifo])
with open(fifo, 'wb') as file:
    file.write("Text sent to handler for display")
os.remove(fifo)
p.wait()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!