Guest User

Untitled

a guest
Nov 14th, 2018
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. import sys
  2. import os
  3. import subprocess
  4. from subprocess import Popen, PIPE
  5. import threading
  6.  
  7.  
  8. class LocalShell(object):
  9. def __init__(self):
  10. pass
  11. def run(self):
  12. env = os.environ.copy()
  13. p = Popen('open -a Terminal -n', stdin=PIPE, stdout=PIPE, stderr=subprocess.STDOUT, shell=True, env=env)
  14. sys.stdout.write("Started Local Terminal...rnrn")
  15.  
  16. def writeall(p):
  17. while True:
  18. # print("read data: ")
  19. data = p.stdout.read(1).decode("utf-8")
  20. if not data:
  21. break
  22. sys.stdout.write(data)
  23. sys.stdout.flush()
  24.  
  25. writer = threading.Thread(target=writeall, args=(p,))
  26. writer.start()
  27.  
  28. try:
  29. while True:
  30. d = sys.stdin.read(1)
  31. if not d:
  32. break
  33. self._write(p, d.encode())
  34.  
  35. except EOFError:
  36. pass
  37.  
  38. def _write(self, process, message):
  39. process.stdin.write(message)
  40. process.stdin.flush()
Add Comment
Please, Sign In to add comment