Issue
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
Solution
The solution is to clean the buffer when printing and for this there are several options:
- flush=True
print('hello \n'. flush=True)
- Set the PYTHONUNBUFFERED environment variable to "1":
PYTHONUNBUFFERED=1 python3 qt_redirect.py > file.txt
- User the python "-u" option:
python3 -u qt_redirect.py > file.txt
Answered By - eyllanesc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.