Starting New Process

Jean-Paul Calderone exarkun at divmod.com
Thu Jun 1 11:09:14 EDT 2006


On 1 Jun 2006 07:34:23 -0700, D <duncanm255 at hotmail.com> wrote:
>Hello, I need to write a server program that performs the following
>tasks:
>
>1)  Listens on TCP port 5555 for a connection
>2)  When client connects, launches application (for example, vi), then
>closes connection with client
>3)  Goes back to listening on TCP port 5555 for an incoming connection

Untested:

  from twisted.internet import protocol, reactor

  class ViRunner(protocol.Protocol):
      def connectionMade(self):
          reactor.spawnProcess(
              None,
              '/usr/bin/setsid',
              ['setsid', '/usr/bin/vi'])
          self.transport.loseConnection()

  f = protocol.ServerFactory()
  f.protocol = ViRunner
  reactor.listenTCP(5555, f)
  reactor.run()

Jean-Paul



More information about the Python-list mailing list