我正在尝试运行 PTY 服务器的扭曲文档中的示例代码示例,该服务器在连接时生成 shell。
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()
此代码给出错误“Windows 不支持 usePTY 参数”。我希望有一种解决方法或任何可能有助于在 Windows 上运行它的方法。