I want to output some data from a Python script continuously to another program. As an example I will use cat, this is what currently happens:
If my test1.py script is like this:
print("Hello!")
when I run ./test1.py | cat the output is Hello!, it works because the script terminates immediately after execution.
The problem occurs when I have a script that writes continuously and never terminates like test2.py:
import time
a = 0
while True:
a += 1
print(a)
time.sleep(1)
Then ./test2.py | cat just hangs there because the script is not terminating.
I would like to send one number every second to cat and display it in real time, is it possible?