Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from subprocess import PIPE, STDOUT, Popen
- from threading import Thread
- import sys
- try:
- from queue import Queue, Empty
- except ImportError:
- from Queue import Queue, Empty # python 2.x
- ON_POSIX = 'posix' in sys.builtin_module_names
- def enqueue_output(out, queue):
- while p.poll() is None:
- sys.stdout.flush()
- for line in iter(out.readline, b''):
- queue.put(line)
- out.close()
- p = Popen(['moonlight', 'pair', 'windows'], stdout=PIPE, stderr=STDOUT) #change "windows" to hostname or IP
- q= Queue()
- t = Thread(target=enqueue_output, args=(p.stdout, q))
- t.daemon = True
- t.start()
- while p.poll() is None:
- try:
- line = q.get(timeout=.5)
- except Empty:
- if p.poll() is not None:
- break
- print('\x1b[1;31;40m'+'no output yet'+'\x1b[0m')
- else:
- print('\x1b[1;32;40m'+'Queued Output ... '+line.decode()+'\x1b[0m')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement