<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Courier New";
        color:windowtext;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-family:"Courier New"'>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.  <o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>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:<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>    from twisted.internet import reactor, protocol<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>    class FakeTelnet(protocol.Protocol):<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>        commandToRun = ['c:\\Windows\\System32\\cmd.exe']<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>        def connectionMade(self):<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>            print 'connection made'<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>            self.propro = ProcessProtocol(self)<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>            reactor.spawnProcess(self.propro, self.commandToRun[0], <o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>                                 self.commandToRun, os.environ)<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>        def dataReceived(self, data):<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>            self.propro.transport.write(data)<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>        def conectionLost(self, reason):<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>            print 'connection lost'<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>            self.propro.tranport.loseConnection()<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>    class ProcessProtocol(protocol.ProcessProtocol):<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>        def __init__(self, pr):<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>            self.pr = pr<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>        def outReceived(self, data):<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>            self.pr.transport.write(data)<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>        def processEnded(self, reason):<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>            print 'protocol connection lost'<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>            self.pr.transport.loseConnection()<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>    f = protocol.Factory()<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>    f.protocol = FakeTelnet<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>    reactor.listenTCP(5823, f)<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>    reactor.run()<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>Run the above code on Windows, and telnet to localhost 5823.<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>After you get the CMD.exe prompt, try to launch python.  This is what you'll<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>see:<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>    Microsoft Windows [Version 6.3.9600]<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>    (c) 2013 Microsoft Corporation. All rights reserved.<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>    C:\Temp>python<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>    python<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>That’s it. Hitting enter just drops down to another next blank line. <o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>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 CMD.exe prompt.<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>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.<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>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....<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>FYI – once we get this worked out, we’d be happy to share the code.<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>Thanks<o:p></o:p></span></p><p class=MsoNormal><span style='font-family:"Courier New"'>Jim C.<o:p></o:p></span></p></div></body></html>