Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #17764
| Date | 2011-12-23 12:21 +1100 |
|---|---|
| From | Cameron Simpson <cs@zip.com.au> |
| Subject | Re: reading multiline output |
| References | <FFB26576-7928-4E01-8D56-26071FDB39CE@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4010.1324603767.27778.python-list@python.org> (permalink) |
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>)
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: reading multiline output Cameron Simpson <cs@zip.com.au> - 2011-12-23 12:21 +1100
csiph-web