Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何仅存储从子流程返回的最后一行?
特别是,我从 python 调用了一个子进程,它返回了很多输出行。子进程在一些不可预测(可能很长)的时间后终止,我只需要处理来自 STDOUT 的最后一行。
我可以以某种方式避免存储整个输出并等待最后一个吗?
在阅读最后一行之前,您必须处理(并丢弃)每一行。
所以你可以做类似的事情
line = None for line in proc.stdout: pass # now line is either the last line or None. if line is not None: process(line)