Wanted to save the console output from terminal to a file, by redirecting stdout with '>', like wither of these lines, and none was working:
./service_explorer.py --name SensorTag > conout.txt
python3 ./service_explorer.py --name SensorTag > conout.txt
python3 -u ./service_explorer.py --name SensorTag > conout.txt- either of the above lines will produce an empty file 'conout.txt', all the text is seen in the terminal only
- added -u (unbuffered) in the shebang or in the command line doesn't fix it, so I don't think it is about flushing buffers
- other redirections from a Python test of a single line 'print ("ok")', does work, the text 'ok' is put in 'conout.txt'
- found something that might be related with the issue, though I'm not sure if this is the cause, or how to overcome it
https://bugs.python.org/issue44158The troubling Python file, 'service_explorer.py', is an example from a python module for Bluetooth LE, 'bleak', and the code is working OK in a terminal:
https://github.com/hbldh/bleak/blob/master/examples/service_explorer.pyFor now, as a workaround I can manually copy/paste the text from the terminal, but I plan to use 'bleak' to write code that will print to stdout in order to be redirected and/or piped to other command line tools.
- 1. Why bash redirection is not working here?
- 2. What to do, to produce redirectable stdout (for other Python programs using the 'bleak' module)?