We've been experimenting with creating an SSH virtual server for Windows
based on conch. We've made good process, but we've run into a problem
running child processes (children of spawnProcess()), in that stdout does
not make it back to the client.
I can demonstrate the problem using the example ptyserv.py script with a
slight change for Windows. Here's the code to demonstrate the problem:
from twisted.internet import reactor, protocol
commandToRun = ['c:\\Windows\\System32\\cmd.exe']
print 'connection made'
self.propro = ProcessProtocol(self)
def dataReceived(self, data):
def conectionLost(self, reason):
print 'connection lost'
def __init__(self, pr):
self.pr = pr
def outReceived(self, data):
def processEnded(self, reason):
print 'protocol connection lost'
f = protocol.Factory()
f.protocol = FakeTelnet
Run the above code on Windows, and telnet to localhost 5823.
After you get the CMD.exe prompt, try to launch python. This is what you'll
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.
That's it. Hitting enter just drops down to another next blank line.
Now what's interesting is that writes to stdin of the spawned CMD.exe get
there. You can see this by pressing <CTRL>-D. The python subprocess will
exit and you'll still be connected to your telnet session, now back at the
I've experimented with modifying twisted.internet._dumbwin32proc.py so that
the DuplicateHandle() calls (lines 147 - 163) are not called, thinking that
inheritance was the cause, but no-go. I've also tried adding calls to
msvcrt.set_mode() to os.O_BINARY to make sure windows isn't somehow cooking
the child processes output, but that had no effect either.
I've been banging my head against this for a week and I've reached a stuck
point. I was wondering if someone could point me towards where I'm going
wrong. Any advice would be appreciated....
FYI - once we get this worked out, we'd be happy to share the code.