Reputation: 155
I have the following super simple qt application:
import sys
from PyQt5 import QtWidgets
print('hello \n')
app = QtWidgets.QApplication(sys.argv)
app.exec_()
When executing it normally with terminal hello message is shown, h/w when redirecting stdout to a file:
python3 qt_redirect.py > file.txt
the file remains empty.
Help me guys, what am I missing here?
python version - 3.6.9 PyQt5 version - 5.14.1 os - ubuntu 18.04.3 LTS
Upvotes: 2
Views: 337
Reputation: 243955
The solution is to clean the buffer when printing and for this there are several options:
print('hello \n'. flush=True)
PYTHONUNBUFFERED=1 python3 qt_redirect.py > file.txt
python3 -u qt_redirect.py > file.txt
Upvotes: 3