# HG changeset patch # User Dirk Olmes # Date 1411260324 -7200 # Node ID dfefc456dc93eb682242dda1b59bef434d59850d # Parent d666b9fe5663c99af7b2fc0134f642dfa3347b03 capture the output of the running executable (from a different thread) diff -r d666b9fe5663 -r dfefc456dc93 RemoteViewer/Viewer.py --- a/RemoteViewer/Viewer.py Sat Sep 20 06:44:47 2014 +0200 +++ b/RemoteViewer/Viewer.py Sun Sep 21 02:45:24 2014 +0200 @@ -1,13 +1,32 @@ import subprocess +from threading import Thread + +class ReadThread(Thread): + def __init__(self, output): + super(ReadThread, self).__init__() + self.daemon = True + self.output = output + + def run(self): + for line in iter(self.output.readline, b''): + line = line.decode('utf-8') + line = line.rstrip('\n') + print(line) class AbstractViewer(object): def __init__(self, connection): self.connection = connection + self.process = None def open(self): command = self.buildCommand() - print(command) - subprocess.call(command) + self.process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + self.__startLogThread(self.process.stdout) + self.process.wait() + + def __startLogThread(self, output): + readThread = ReadThread(output) + readThread.start() class VncViewer(AbstractViewer): def buildCommand(self):