Guest User

Untitled

a guest
Aug 22nd, 2025
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #!/usr/bin/python2 -tt
  2. # vim:set fileencoding=utf-8
  3.  
  4. from subprocess import *
  5. import sys
  6. import os, select
  7.  
  8. special = {
  9. # define new unicode nethack/tradewars glyphs here
  10. }
  11.  
  12. if len(sys.argv) < 2:
  13. print "usage: ibmfilter [command]"
  14. print "Runs command in a subshell and translates its output from ibm473 codepage to UTF-8."
  15. sys.exit(0)
  16.  
  17. handle = Popen(sys.argv[1:], stdout=PIPE, bufsize=1)
  18. buf = handle.stdout.read(1)
  19. while buf != '':
  20. if buf in special:
  21. out = special[buf]
  22. else:
  23. out = buf.decode('ibm437')
  24. writeable = select.select([], [sys.stdout], [], 5)[1]
  25. if not writeable:
  26. os.kill(handle.pid)
  27. os.system('reset')
  28. raise Exception("Timed out while waiting for stdout to be writeable...")
  29. sys.stdout.write(out.encode("UTF-8"))
  30.  
  31. buf = handle.stdout.read(1)
  32.  
  33. handle.wait()
  34.  
Advertisement
Add Comment
Please, Sign In to add comment