【发布时间】:2013-02-28 15:27:26
【问题描述】:
我正在学习使用 twisted(最新 12.3.0 版本),作为对移动应用进行一些简单服务器端处理的一种方式。
我的第一个任务本质上是在日志文件上运行“tail”命令,并将后处理的找到的行传送到移动应用程序。这应该很容易......
现在在 TwistedMatrix 网站上的文档中有一个“使用进程”页面,我在其中得到了以下代码:
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()
它与“Doing the Easy Way”下发布的代码 sn-p 99.9% 相同。唯一的变化是twisted应该执行的shell命令(在我的Mac上我似乎没有fortune命令)。
当我尝试使用 telnet 从第二个终端连接 10999 端口时启动示例代码后,我收到此错误:
[失败实例:回溯(没有帧的失败)::得到标准错误:'在 execvpe tail -n 100 /var/log/system.log [\'tail -n 100 /var/log/system.log\'] 在环境 id 4315532016\n:Traceback (大多数 最近通话最后):\n 文件 “/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” , 第 420 行,在 _fork\n 可执行文件、参数、环境中)\n 文件 “/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” , 第 466 行,在 _execChild\n os.execvpe(executable, args, 环境)\n 文件 "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", 第 353 行,在 execvpe\n _execvpe(file, args, env)\n 文件 "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", 第 368 行,在 _execvpe\n func(file, *argrest)\nOSError: [Errno 2] 否 这样的文件或目录\n']
我没有看到任何明显的原因为什么代码应该使用 [Errno 2] No such file or directory\n'] 错误提交..
蒂亚
【问题讨论】: