Skip to content

Instantly share code, notes, and snippets.

@sjml
Last active February 28, 2019 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sjml/93b8f0f746aa90babaffb5a9fafec44b to your computer and use it in GitHub Desktop.
Save sjml/93b8f0f746aa90babaffb5a9fafec44b to your computer and use it in GitHub Desktop.
watch hex output live
# monitors a process that is outputting a stream of bytes and prints them live in hex form to stdout.
# could be made more pretty with ncurses and the like, but this does what it needs to do.
import sys
import subprocess
subprocess.run(["tput", "smcup"])
proc = subprocess.Popen(sys.argv[1:], bufsize=0, stdout=subprocess.PIPE)
try:
for c in iter(lambda: proc.stdout.read(1), b""):
sys.stdout.write("%02X " % c[0])
sys.stdout.flush()
except KeyboardInterrupt:
sys.stdout.write("\n")
sys.stdout.flush()
finally:
subprocess.run(["tput", "rmcup"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment