我需要将我的Perl日志处理脚本移植到Python。 下面是一个我可以使用的Perl脚本的简单例子:
#!/usr/local/bin/perl $|=1; # Use unbuffered output while(<>) { system("beep"); }
正如你可能看到的,我告诉系统在发出请求testing脚本时发出嘟嘟声。 一切工作正常,但是当我尝试这样的Python脚本:
import sys import os for line in sys.stdin: os.system('beep')
一切运行,但系统不会在请求后发出哔哔声。 这里是我和我在我的apacheconfiguration文件中使用的行:
CustomLog "|perl /var/web/onhit.pl" "onhit" <-OLD LINE CustomLog "|python /var/web/onhit.py" "onhit" <-NEW LINE
我在Python邮件列表上关注这封电子邮件 。 任何人有一个想法,为什么这是行不通的?
编辑:我知道这个问题有关“sys.stdin行”。 由于某些原因,它只是没有检测到任何标准input。 不过,我不知道它是我的python脚本还是我的apacheconfiguration引起的。
你从哪里发出哔哔声 ? 你有没有尝试把这个哔声命令的完整path?
编辑添加代码示例。
上次我在python中剽窃了一些东西,把stdin读成pipe道,我的代码看起来像这样。
#!/usr/bin/python import sys while 1: line = sys.stdin.readline() if not line: break else: print >> sys.stdout, 'got: %s' % line.strip() sys.stdout.flush()
低挂果:path,权限,所有权。