I am trying to run the sample code example from the twisted documentation for a PTY server that spawns a shell on connection.

from twisted.internet import reactor, protocol

class FakeTelnet(protocol.Protocol):
    commandToRun = ['/bin/sh'] # could have args too
    dirToRunIn = '/tmp'
    def connectionMade(self):
        print 'connection made'
        self.propro = ProcessProtocol(self)
        reactor.spawnProcess(self.propro, self.commandToRun[0], self.commandToRun, {},
                             self.dirToRunIn, usePTY=1)
    def dataReceived(self, data):
        self.propro.transport.write(data)
    def conectionLost(self, reason):
        print 'connection lost'
        self.propro.tranport.loseConnection()

class ProcessProtocol(protocol.ProcessProtocol):

    def __init__(self, pr):
        self.pr = pr

    def outReceived(self, data):
        self.pr.transport.write(data)

    def processEnded(self, reason):
        print 'protocol conection lost'
        self.pr.transport.loseConnection()

f = protocol.Factory()
f.protocol = FakeTelnet
reactor.listenTCP(5823, f)
reactor.run()

This code gives an error "The usePTY parameter is not supported on Windows". I was hoping for a workaround or anything that might help running it on windows.

有帮助吗?

解决方案

Trying to run this code on Windows is somewhat nonsensical. As a very basic level, /bin/sh is not available on Windows, so it would fail there.

Secondly, and more directly to the point of your question: usePTY uses a PTY, or pseudo-terminal, a concept which does not exist on Windows. It is very definitely not supported.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top