I am trying to convert vmstat output to a CSV file using Python, so I use something like this to convert to CSV and add the date and time as coloumns:
vmstat 5 | python myscript.py >> vmstat.log
The problem I encountered is blocking while trying to iterate sys.stdin. It seems that the input buffer is not cleared. I do not want to loop endlessly and record the processor time, as I try to measure this. Here's a simple demo that blocks line 3:
import sys for line in sys.stdin: sys.stdout.write(line) sys.stdout.flush()
Is there an easy way to directly access the stream, as grep does, without pausing when the input buffer is full?
python
Gareth davidson
source share