Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #17765
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.chainon-marquant.org!news-transit.tcx.org.uk!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <macsmith.us@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'mrab': 0.04; 'chunk': 0.07; 'terminated': 0.07; '>>>>': 0.09; 'pos': 0.09; 'output': 0.10; 'am,': 0.12; 'def': 0.13; 'received:209.85.210.174': 0.13; 'received:mail-iy0-f174.google.com': 0.13; 'helped.': 0.16; 'read()': 0.16; 'wrote:': 0.18; 'thanks,': 0.18; '>>>': 0.18; 'suggest': 0.20; 'header:In-Reply-To:1': 0.22; 'command': 0.24; 'url:mailman': 0.28; 'yield': 0.29; 'skip:b 20': 0.29; 'correct': 0.29; 'lines': 0.30; 'hi,': 0.32; 'break': 0.32; 'url:listinfo': 0.32; 'message-id:@gmail.com': 0.33; 'to:addr:python-list': 0.34; 'file.': 0.34; 'parse': 0.34; 'url:python': 0.36; 'charset:us- ascii': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'using': 0.38; 'some': 0.38; 'received:209.85': 0.38; 'url:org': 0.39; 'should': 0.39; 'received:209': 0.40; 'to:addr:python.org': 0.40; 'header:Message-Id:1': 0.62; 'kindly': 0.65; 'received:10.10': 0.68; 'alternative.': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=content-type:mime-version:subject:from:in-reply-to:date :content-transfer-encoding:message-id:references:to:x-mailer; bh=Z7tGH+K6S0MhMDNoTvqB55LbrMzhZhzdBOOCPpwxZgo=; b=dVZFCVfmgzZexmtMRwfvRgcSCoRXs+2YeTMS9gKJnmOJ60OqpBaZk1eu81fp7xya3s v9l4zGRsYsvJG34yf6zjKBOjcaTxo+DU3P82J02QGpJQTt6L5treHpSFFMZN0oTvVI3Q ZjZYWomoAQ5U/wZAppmcC8dQQKRw7gyr/U2xU= |
| Content-Type | text/plain; charset=us-ascii |
| Mime-Version | 1.0 (Apple Message framework v1251.1) |
| Subject | Re: reading multiline output |
| From | Mac Smith <macsmith.us@gmail.com> |
| In-Reply-To | <4EF3D6F8.3020203@mrabarnett.plus.com> |
| Date | Fri, 23 Dec 2011 07:35:23 +0530 |
| Content-Transfer-Encoding | quoted-printable |
| References | <79DF8234-67BF-4297-ACE6-8D091D05B3E9@gmail.com> <EAC763DC-04F6-497F-8455-1CF40A0ACC2E@gmail.com> <4EF3CF8B.4060005@mrabarnett.plus.com> <FFB26576-7928-4E01-8D56-26071FDB39CE@gmail.com> <4EF3D6F8.3020203@mrabarnett.plus.com> |
| To | python-list@python.org |
| X-Mailer | Apple Mail (2.1251.1) |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4011.1324605938.27778.python-list@python.org> (permalink) |
| Lines | 51 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1324605938 news.xs4all.nl 6965 [2001:888:2000:d::a6]:39060 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:17765 |
Show key headers only | View raw
On 23-Dec-2011, at 6:48 AM, MRAB wrote: > On 23/12/2011 01:07, Mac Smith wrote: >> >> On 23-Dec-2011, at 6:17 AM, MRAB wrote: >> >>> On 23/12/2011 00:33, Mac Smith wrote: >>>> Hi, >>>> >>>> >>>> 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. >> > Try telling it how much to read with read(size): > > def read_lines(output, line_ending="\n"): > buffer = "" > > while True: > chunk = output.read(1024) > if not chunk: > break > > buffer += chunk > > while True: > pos = buffer.find(line_ending) > if pos < 0: > break > > pos += len(line_ending) > yield buffer[ : pos] > buffer = buffer[pos : ] > > if buffer: > yield buffer > -- > http://mail.python.org/mailman/listinfo/python-list thanks, this helped. just need to correct line_ending="\n" should be line_ending="\r"
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: reading multiline output Mac Smith <macsmith.us@gmail.com> - 2011-12-23 07:35 +0530
csiph-web