Skip to content

Instantly share code, notes, and snippets.

@tomprince
Forked from coder46/process.py
Created March 8, 2014 00:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomprince/9423257 to your computer and use it in GitHub Desktop.
Save tomprince/9423257 to your computer and use it in GitHub Desktop.
import sys
print "HELLO WORLD !!!"
for line in sys.stdin:
print line
#!/usr/bin/env python
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
from twisted.internet import protocol
from twisted.internet import reactor
class MyPP(protocol.ProcessProtocol):
def connectionMade(self):
print "connectionMade!"
'''
for i in range(self.verses):
self.transport.write("Aleph-null bottles of beer on the wall,\n" +
"Aleph-null bottles of beer,\n" +
"Take one down and pass it around,\n" +
"Aleph-null bottles of beer on the wall.\n")
self.transport.closeStdin() # tell them we're done
'''
#pass
def outReceived(self, data):
print "outReceived! with %d bytes!" % len(data)
print data
self.transport.write("SAME TO YOU")
self.transport.closeStdin() # tell them we're done
def errReceived(self, data):
print "errReceived! with %d bytes!" % len(data)
def inConnectionLost(self):
print "inConnectionLost! stdin is closed! (we probably did it)"
def outConnectionLost(self):
print "outConnectionLost! The child closed their stdout!"
def errConnectionLost(self):
print "errConnectionLost! The child closed their stderr."
def processExited(self, reason):
print "processExited, status %d" % (reason.value.exitCode,)
def processEnded(self, reason):
print "processEnded, status %d" % (reason.value.exitCode,)
print "quitting"
reactor.stop()
pp = MyPP()
reactor.spawnProcess(pp, "python", ["python", "-u", "hello.py"], {})
reactor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment