简体   繁体   English

如何将Python脚本的输出重定向到终端

[英]How to redirect output of Python script to terminal

How can I redirect my Python script output to one of the open terminal windows under Ubuntu? 如何将我的Python脚本输出重定向到Ubuntu下打开的终端窗口之一? The script is spawned by KMail filtering rule. 该脚本由KMail过滤规则生成。

Creating a simple socket server would be one method… But I'd probably use fifos: 创建一个简单的套接字服务器将是一种方法……但是我可能会使用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 然后,您可以使用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 然后您可以使用tail -f /tmp/my_log

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM