I have a python prog that I want to behave like a linux cmd when output is produced. The prog uses 'print()' and when run on the cmd line the printed stuff is clearly visible on the terminal. When I launch the prog with bash output redirect into a file the file stays empty. What's the mistake I'm making?
The printing part of the prog:
chktime = 0
chkper = 10
while True:
if time.time() - chktime > chkper:
chktime = time.time()
diskusepct = get_asus_diskusepct()
print('Asus tmpfs free: ' + diskusepct)
if float(diskusepct) > 95.0:
with open("asus_syslog.log", 'w') as sl:
sl.write(get_asus_syslog())
else:
print('Wait')
time.sleep(1)
From cmd line (as expected):
rpi4b:~/python $ ./asus_diskwatch_v1.0.py
Asus tmpfs free: 1
Wait
Wait
Wait
Wait
With redirect (unexpected):
~/python $ ./asus_diskwatch_v1.0.py > asus_diskwatch.log &
[2] 4415
~/python $ cat asus_diskwatch.log
<nothing>
Feedback is appreciated.