title: twisted Using Processes
body: <p>I am learning to use twisted (latest 12.3.0 release), as a way to do some simple server side processing for a mobile app.</p>
  
  <p>My first assigment is essentially to run a 'tail' command on a logs file and deliver the postprocessed found lines to the mobile app. That should be easy...</p>
  
  <p>Now in the docs on the TwistedMatrix site there is a 'Using Processes' page, where I got the following code:</p>
  
  <hr>
  
  <pre><code>from twisted.internet import protocol, utils, reactor
  from twisted.python import failure
  from cStringIO import StringIO
  
  class CommandRunner(protocol.Protocol):
  
      #command = "ls /"
      command = "tail -n 100 /var/log/system.log"
  
      def connectionMade(self):
          output = utils.getProcessOutput(self.command)
          output.addCallbacks(self.writeResponse, self.noResponse)
  
      def writeResponse(self, resp):
          self.transport.write(resp)
          self.transport.loseConnection()
  
      def noResponse(self, err):
  
          print err
          self.transport.write("Houston, we have an error!\n")
          self.transport.loseConnection()
  
  
  if __name__ == '__main__':
      f = protocol.Factory()
      f.protocol = CommandRunner
      reactor.listenTCP(10999, f)
      reactor.run()
  </code></pre>
  
  <p>It is 99.9% identical to the published code snippet under the 'Doing it the Easy Way'. The only change is the shell command that twisted should execute (on my Mac I do not seem to have the fortune command).</p>
  
  <p>After launching the sample code when I try to connect on the 10999 port from a second terminal with telnet I get this error:</p>
  
  <blockquote>
    <p>[Failure instance: Traceback (failure with no frames): : got stderr: 'Upon
    execvpe tail -n 100 /var/log/system.log [\'tail -n 100
    /var/log/system.log\'] in environment id 4315532016\n:Traceback (most
    recent call last):\n  File
    "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Twisted-12.3.0-py2.7-macosx-10.6-intel.egg/twisted/internet/process.py",
    line 420, in _fork\n    executable, args, environment)\n  File
    "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Twisted-12.3.0-py2.7-macosx-10.6-intel.egg/twisted/internet/process.py",
    line 466, in _execChild\n    os.execvpe(executable, args,
    environment)\n  File
    "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py",
    line 353, in execvpe\n    _execvpe(file, args, env)\n  File
    "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py",
    line 368, in _execvpe\n    func(file, *argrest)\nOSError: [Errno 2] No
    such file or directory\n']</p>
  </blockquote>
  
  <p>I do not see any obvious reason why the code should file with a [Errno 2] No such file or directory\n'] error..</p>
  
  <p>Tia</p>