[Tutor] Subprocess.Popen process seems to be outputting to stdout even though redirected ?

dave selby dave6502 at gmail.com
Sun Jun 10 11:47:36 CEST 2012


This list is amazing, I scratch my head, think and think then finally
post a question, maybe its the act of spelling it out, ps ax showed 2
x 'tail' processes, I am guessing zombies of previous attempts, killed
them, all works AOK now


On 10 June 2012 10:06, dave selby <dave6502 at gmail.com> wrote:
> 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



-- 

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