Prev | Index | Next

spawnProcess example

class _BackRelay(protocol.ProcessProtocol):
    def __init__(self, deferred):
        self.deferred = deferred
        self.s = StringIO.StringIO()
    def errReceived(self, text):
        self.deferred.errback(
            failure.Failure(IOError()))
        self.deferred = None
        self.transport.loseConnection()
    def outReceived(self, text):
        self.s.write(text)
    def processEnded(self, reason):
        if self.deferred is not None:
            result = self.s.getvalue()
            self.deferred.callback(result)