Created
March 21, 2021 21:53
-
-
Save Peetz0r/b0a21d2eb0a1a097d1335a8b9f5ff548 to your computer and use it in GitHub Desktop.
btmgmt doesn't wanna be redirected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
peter@doosje /tmp> ./test.py | |
normal stdout (should be empty): | |
Index list with 1 item | |
hci0: Primary controller | |
addr 9C:FC:E8:F2:41:6B version 10 manufacturer 2 class 0x3c0104 | |
supported settings: powered connectable fast-connectable discoverable bondable link-security ssp br/edr hs le advertising secure-conn debug-keys privacy configuration static-addr phy-configuration wide-band-speech | |
current settings: powered ssp br/edr le secure-conn | |
name doosje | |
short name | |
hci0: Configuration options | |
supported options: public-address | |
missing options: | |
end of normal stdout | |
redirected stdout: | |
Hello World! | |
redirected stderr: | |
peter@doosje /tmp> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python3 | |
import sys, io, btmgmt | |
print('normal stdout (should be empty):') | |
ogo = sys.stdout | |
oge = sys.stderr | |
sys.stdout = io.StringIO() | |
sys.stderr = io.StringIO() | |
print('Hello World!') | |
btmgmt.command('info') | |
o = sys.stdout | |
e = sys.stderr | |
sys.stdout = ogo | |
sys.stderr = oge | |
o.seek(0) | |
e.seek(0) | |
print('end of normal stdout\n\n') | |
print('redirected stdout:') | |
print(o.read()) | |
print('redirected stderr:') | |
print(e.read()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment