Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2020
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. from subprocess import PIPE, STDOUT, Popen
  2. from threading import Thread
  3. import sys
  4.  
  5. try:
  6. from queue import Queue, Empty
  7. except ImportError:
  8. from Queue import Queue, Empty # python 2.x
  9. ON_POSIX = 'posix' in sys.builtin_module_names
  10.  
  11. def enqueue_output(out, queue):
  12. while p.poll() is None:
  13. sys.stdout.flush()
  14. for line in iter(out.readline, b''):
  15. queue.put(line)
  16. out.close()
  17.  
  18. p = Popen(['moonlight', 'pair', 'windows'], stdout=PIPE, stderr=STDOUT) #change "windows" to hostname or IP
  19. q= Queue()
  20. t = Thread(target=enqueue_output, args=(p.stdout, q))
  21. t.daemon = True
  22. t.start()
  23.  
  24. while p.poll() is None:
  25. try:
  26. line = q.get(timeout=.5)
  27. except Empty:
  28. if p.poll() is not None:
  29. break
  30. print('\x1b[1;31;40m'+'no output yet'+'\x1b[0m')
  31. else:
  32. print('\x1b[1;32;40m'+'Queued Output ... '+line.decode()+'\x1b[0m')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement