如何使外壳输出重定向(大于)写剧本时仍在运行? [英] How to make shell output redirect (>) write while script is still running?

查看:146
本文介绍了如何使外壳输出重定向(大于)写剧本时仍在运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的永远不会终止短的脚本。该脚本不断生成,我有现在,然后检查每个输出。我运行它的计算机实验室通过SSH,并在该机器上输出重定向到一个文件在我的public_html文件夹中。

I wrote a short script that never terminates. This script continuously generates output that I have to check on every now and then. I'm running it on a lab computer through SSH, and redirecting the output to a file in my public_html folder on that machine.

python script.py > ~/public_html/results.txt

然而,这样做的结果不会立即显示出来,当我刷新地址。结果表明,当我终止程序,但正如我所说,它本身并不能停止。是不是重定向(> )的懒惰与写作?有没有一种方法不断(或间隔)更新文件中的结果?

However, the results don't show up immediately when I refresh the address. The results show up when I terminate the program, but as I said, it doesn't halt by itself. Is that redirect (>) being lazy with with writing? Is there a way to continuously (or with an interval) update the results in the file?

或者是它,而仍然被写它不更新文件的网络服务器?

Or is it the webserver that doesn't update the file while it is still being written?

推荐答案

您需要刷新输出 sys.stdout.flush()(或水木清华),如果你想马上看到它。请参见

You need to flush the output sys.stdout.flush() (or smth) if you want to see it immediately. See this

这篇关于如何使外壳输出重定向(大于)写剧本时仍在运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆