real time updating of popen, bufsize=0 problems

ianaré ianare at gmail.com
Fri Apr 6 16:07:32 EDT 2007


On Apr 6, 3:59 pm, Rob Wolfe <r... at smsnet.pl> wrote:
> "ianaré" <ian... at gmail.com> writes:
> > hey all, I'm trying to get real time updates of batch file output.
>
> [...]
>
> > So I tried subprocess:
> > proc = subprocess.Popen('"C:/path/to/test.bat"', bufsize=0,
> >   stdout=subprocess.PIPE)
>
> Instead of that:
>
> > for line in proc.stdout:
> >     self.display.WriteText(line)
>
> try that:
>
> while True:
>     line = proc.stdout.readline()
>     if not line: break
>     self.display.WriteText(line)
>
> When a file is used in a for loop it works like an iterator.
> You can read details here (description of method ``next``):http://docs.python.org/lib/bltin-file-objects.html
>
> --
> HTH,
> Rob

Rob, you are the man =) thanks!




More information about the Python-list mailing list