[Tutor] Subprocess.Popen process seems to be outputting to stdout even though redirected ?
dave selby
dave6502 at gmail.com
Sun Jun 10 11:06:39 CEST 2012
I have a simple script to tail a log file for an error string, it
works AOK but there is an unexpected side effect, when I run it in a
shell.
if I
echo "ERROR TEST" >> LOG
in a separate shell, I get the following from the script
ERROR TEST
GOT YA :)
ERROR TEST
So it looks like I am getting stdout from the tail -f, and two copies
of it ?, stdout should be piped to subprocess.stdout
tail = subprocess.Popen(['tail', '-f', LOG_FILE], shell=False,
stdout=subprocess.PIPE)
for out in iter(tail.stdout.readline, ''):
out_str = out.rstrip('\n')
if out_str.find('ERROR') != -1:
print 'GOT YA :)'
time.sleep(1)
Any ideas anyone ?
Cheers
Dave
--
Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
More information about the Tutor
mailing list