0

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.

4
  • Are you talking about virtual terminals or about terminal windows in X (similar to xterm)? Commented Aug 9, 2011 at 15:17
  • Talking about terminal in X, which I open by running terminal application from Applications->Accessories. Commented Aug 9, 2011 at 15:19
  • 3
    The typical solution (to what I think is your underlying problem) is to have the script append to a log file on disk, and then use tail -f on 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. Commented Aug 9, 2011 at 15:20
  • 1
    @Henning Makholm: Please put that as an answer. Commented Aug 9, 2011 at 15:22

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

os.mkfifo() exists, so your first example could include that.
That's very true — I hadn't considered it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.