How can I redirect my Python script output to one of the open terminal windows under Ubuntu? The script is spawned by KMail filtering rule.
1 Answer
Creating a simple socket server would be one method… But I'd probably use fifos:
$ mkfifo /tmp/my_fifo
$ cat producer.py
f = open("/tmp/my_fifo", "w")
f.write("hello, world!\n")
f.close()
Then you could read from it using cat /tmp/my_fifo
Or a simple log file:
$ cat producer.py
f = open("/tmp/my_log", "a")
f.write("hello, world!\n")
f.close()
Then you could read from it using tail -f /tmp/my_log
2 Comments
glglgl
os.mkfifo() exists, so your first example could include that.David Wolever
That's very true — I hadn't considered it.
tail -fon the log file in a terminal window when you want to watch things in (almost) real time. You'll want to rotate the log files once in a while.