I have a scripts which generates huge amount of data and dump it to stdout
. Using less
it is easy to scroll through it:
./myscript | less
If myscript
is running and providing data continuously, the latest less
can update the view automatically (if the stdout
buffer is flushed). This simple Python script shows this case:
import time
import os
import sys
for i in range(1000):
stream = sys.stdout.buffer
msg = str(i) + "\n"
stream.write(msg.encode())
stream.flush()
if (i + 0) % 100 == 0:
time.sleep(5)
python3 pipe.py | less
What I want to achieve is that the script only provides the next page of data if the user reached the end of the scrolling in less
(instead of automatic update which the script above does).
Is it possible to do this? (Note the Python script is just an example, the question is much more about the shell part.)