Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #17764 > unrolled thread

Re: reading multiline output

Started byCameron Simpson <cs@zip.com.au>
First post2011-12-23 12:21 +1100
Last post2011-12-23 12:21 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: reading multiline output Cameron Simpson <cs@zip.com.au> - 2011-12-23 12:21 +1100

#17764 — Re: reading multiline output

FromCameron Simpson <cs@zip.com.au>
Date2011-12-23 12:21 +1100
SubjectRe: reading multiline output
Message-ID<mailman.4010.1324603767.27778.python-list@python.org>
On 23Dec2011 06:37, Mac Smith <macsmith.us@gmail.com> wrote:
| On 23-Dec-2011, at 6:17 AM, MRAB wrote:
| > On 23/12/2011 00:33, Mac Smith wrote:
| >> I have started HandBrakeCLI using subprocess.popen but the output is
| >> multiline and not terminated with \n so i am not able to read it
| >> using readline() while the HandBrakeCLI is running. kindly suggest
| >> some alternative. i have attached the output in a file.
| >> 
| > The lines are terminated with \r, so read with read() and then split on
| > "\r".
| 
| read() will read the complete output and than i will be able to parse
| it, i want to read the output of the command in realtime.

You can read a limited number of bytes - for your purposes this needs to
be 1 byte at a time. Very inefficient, but you can do what you need.
Write a little function that gathers single bytes until "\r" and then
returns them joined into a string.

Traditionally the way to work with "interactive" facilities like this is
often the "expect" command, and I gather there's a third party Python
module named "pexpect" with that functionality. This:
  http://www.noah.org/wiki/pexpect

And then there's all sorts of read-with-timeout games you can play I
guess...

Note that all this relies on HandBrakeCLI emitting its progress messages
in a timely (== unbuffered) manner when its output is a pipe...

Cheers,
-- 
Cameron Simpson <cs@zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

It's better to be DoD and cool, than to get a life and be uncool!
        - _Harley Davidson & The Marlboro Man_
          (slightly paraphrased by Roar Larsen, DoD#463
                                   <Roar.Larsen@termo.unit.no>)

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web