- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我制作了一个 python 脚本,它使用无限循环与 Web 服务器进行通信。我想将每个通信数据记录到一个文件中,并同时从终端监视它们。所以我使用了这样的 tee 命令。
python client.py | tee logfile
但是,我没有从终端或日志文件中得到任何信息。python脚本工作正常。这里发生了什么?我错过了什么吗?
我们将不胜感激。提前谢谢你。
最佳答案
来自man python
:
-u Force stdin, stdout and stderr to be totally unbuffered. On systems
where it matters, also put stdin, stdout and stderr in binary mode. Note
that there is internal buffering in xreadlines(), readlines() and file-
object iterators ("for line in sys.stdin") which is not influenced by
this option. To work around this, you will want to use "sys.stdin.read‐
line()" inside a "while 1:" loop.
所以你可以做的是:
/usr/bin/python -u client.py >> logfile 2>&1
或者使用tee
:
python -u client.py | tee logfile
关于python - linux tee 不能与 python 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21662783/
我有一个关于 this answer 的问题,如下引用,由 friedo 回答此处的另一个问题。 (我无权对此发表评论,所以我将其作为一个问题提出。) "You can use File::Tee.
我有一个关于 this answer 的问题,在下面引用,由 friedo 在这里回答另一个问题。 (我无权对此发表评论,所以我将此作为问题提出。) "You can use File::Tee. u
您好,我一直在用 C 编写一个 linux shell。我想将我的输出重定向到文件和终端,我发现 tee 是可行的方法。我去了 tee 的 linux 手册页,发现 tee 可以用作函数调用以在 C
有没有办法在发送到文件之前处理来自 tee 的文本? 例如,如果程序输出以下行: stack 11 stack 22 stack 33 serverfault serverfault stack 44
下面是一些关于itertools.tee的测试: li = [x for x in range(10)] ite = iter(li) ========================
我正在将 bash 脚本日志记录移植到 Powershell,它在文件顶部有以下内容: # redirect stderr and stdout backupdir="/backup" logfile
我尝试将 echo 命令保存到日志文件: echo "XXXXX" | tee -a ./directory_with_logs/my_script.log 当文件 my_script.log 存在时
我正在尝试使用 tee 将我的流输出为 1 分钟的片段并同时输出到一个文件中。这是我的命令: ffmpeg -i "rtsp://${cameraIp}:554/axis-media/media.am
我想在 ksh 脚本(使用 exec)中创建一个管道,该管道连接到 tee,并将输出发送到管道。 当前: #Redirect EVERYTHING exec 3>&1 #Save STDOUT as
tee 从标准输入读取并写入标准输出和文件。 some_command |& tee log tee 可以写入压缩文件吗? some_command |& tee -some_option log.b
这个问题已经有答案了: Can you redirect Tee-Object to standard out? (2 个回答) 已关闭去年。 我生成一个 csv 文件: myscript.ps1 |
我有以下代码。 $summary = . { while ($true) { # Generating huge list of psobject } } | Tee-
这个问题已经有答案了: Can you redirect Tee-Object to standard out? (2 个回答) 已关闭去年。 我生成一个 csv 文件: myscript.ps1 |
有人可以帮我解决这个问题吗?我目前正在尝试将查询写入文件,最终将用 notee 关闭它;称呼。我以前使用过发球电话,但由于某种原因,今天我遇到了问题。 这是有问题的语法: tee c:/trash/t
我是 MySQL(或一般 SQL)新手我试图让 MySQL 使用 TEE 命令将时间戳写入带有存储过程的文件中(我不认为我可以使用“select into outfile”,因为我不想删除该文件,我想
我目前正在使用以下内容来捕获进入终端的所有内容并将其放入日志文件中 exec 4&2>&>(tee -a $LOG_FILE) 但是,我不想让颜色转义码/困惑进入日志文件。所以我有这样的东西,有点管用
这个问题在这里已经有了答案: Force line-buffering of stdout in a pipeline (7 个答案) 关闭 9 年前。 我正在运行这样的命令: python myc
我正在尝试在 ubuntu 15.04 上将 tee 命令与 rendercheck 测试一起使用,tee 命令可以很好地处理 6 个 rendercheck 测试,例如: ./renderchec
我想通过使用 while 循环和读取来模拟 shell 脚本中 tee 命令的行为,或者是否可以查看命令的内容。 最佳答案 不确定你在问什么,但为了一个简单的例子,试试这个 - file=$1
我想要这样的东西 $> ps -ax | tee -a processes.txt 在 UNIX C 编程环境中,意味着不通过 shell 脚本。 基本上有一个 API,这样我就可以在 STDIN 和
我是一名优秀的程序员,十分优秀!