1

I need to port my Perl log handling script to Python. Here is a simple example of a Perl script I can use:

#!/usr/local/bin/perl $|=1; # Use unbuffered output while(<>) { system("beep"); } 

As you can probably see, I am telling the system to beep whenever a request is made to test the script. Everything works fine on this one, but when I try a Python script such as this:

import sys import os for line in sys.stdin: os.system('beep') 

everything runs but the system does not beep after a request. Here are the lines I was and am using in my apache configuration file:

CustomLog "|perl /var/web/onhit.pl" "onhit" <-OLD LINE CustomLog "|python /var/web/onhit.py" "onhit" <-NEW LINE 

I am following this email on the Python mailing list. Anyone have an idea why this is not working?

EDIT: I know the problem has something to do with "for line in sys.stdin". For some reason it is just not detecting anything in stdin. I have no idea whether it is my python script or my apache configuration causing this, though.

1
  • If your problem is related to the actual script you might find you get better answers on stackoverflow Commented Aug 20, 2009 at 2:52

2 Answers 2

1

Where are you getting beep from? Have you tried putting in the full path to this beep command?

Edited to add code sample.

Last time I hacked something in python to read stdin as a pipe my code looked like this.

#!/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() 
3
  • Beep is a command on my machine that makes the system beep. It is in the path variable so I do not need to list the full path. I know it is not that line giving me the trouble; that is just a test to see if things are working. Commented Aug 20, 2009 at 2:04
  • This sounds like the most likely reason. Commented Aug 20, 2009 at 6:13
  • Thanks a lot, i guess the guy on the mailing list didn't know what he was talking about. It makes sense that the stdin test should be in a while, and not a for loop. Commented Aug 20, 2009 at 14:27
0

Low hanging fruit: paths, permissions, ownerships.

1
  • Well it doesn't really matter, but onhit.py has execute permissions, and I know all the paths are right. Ownerships are both root. Commented Aug 20, 2009 at 2:49

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.