Using Python's Subprocess to Display Output in New Xterm Window

后端 未结 1 1309
心在旅途
心在旅途 2021-01-15 07:23

I am trying to output different information in two terminals from the same Python script (much like this fellow). The way that my research has seemed to point to is to open

相关标签:
1条回答
  • 2021-01-15 07:59

    This doesn't work because you pipe stuff to xterm itself not the program running inside xterm. Consider using named pipes:

    import os
    from subprocess import Popen, PIPE
    import time
    
    PIPE_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)
    
    0 讨论(0)
提交回复
热议问题