这是行不通的,因为您将内容通过管道传递到
xterm内部而不是内部运行的程序
xterm。考虑使用命名管道:
import osfrom subprocess import Popen, PIPEimport timePIPE_PATH = "/tmp/my_pipe"if not os.path.exists(PIPE_PATH): os.mkfifo(PIPE_PATH)Popen(['xterm', '-e', 'tail -f %s' % PIPE_PATH])for _ in range(5): with open(PIPE_PATH, "w") as p: p.write("Hello world!n") time.sleep(1)


