Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news-out1.kabelfoon.nl!newsfeed.kabelfoon.nl!bandi.nntp.kabelfoon.nl!feed.xsnews.nl!border-1.ams.xsnews.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'mrab': 0.04; 'sorts': 0.04; 'string.': 0.04; 'received:edu.au': 0.07; 'terminated': 0.07; 'python': 0.08; 'relies': 0.09; 'output': 0.10; 'am,': 0.12; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'guess...': 0.16; 'message- id:@cskk.homeip.net': 0.16; 'read()': 0.16; 'received:202.125.174': 0.16; 'received:202.125.174.133': 0.16; 'received:boardofstudies.nsw.edu.au': 0.16; 'received:cskk.homeip.net': 0.16; 'received:harvey.boardofstudies.nsw.edu.au': 0.16; 'received:homeip.net': 0.16; 'received:nsw.edu.au': 0.16; 'cc:addr :python-list': 0.16; 'this:': 0.16; 'wrote:': 0.18; 'bytes': 0.18; 'cc:no real name:2**0': 0.20; 'cheers,': 0.20; 'suggest': 0.20; 'header:In-Reply-To:1': 0.22; 'cc:2**0': 0.24; 'command': 0.24; 'byte': 0.24; 'timely': 0.25; 'module': 0.26; 'function': 0.27; 'gather': 0.29; 'cc:addr:python.org': 0.29; 'url:wiki': 0.29; 'lines': 0.30; 'joined': 0.32; 'header:User-Agent:1': 0.33; 'named': 0.33; 'file.': 0.34; 'parse': 0.34; 'received:au': 0.36; 'charset:us-ascii': 0.37; 'skip:" 10': 0.37; 'but': 0.37; "there's": 0.37; 'using': 0.38; 'purposes': 0.38; 'some': 0.38; 'url:org': 0.39; "it's": 0.40; 'third': 0.40; 'your': 0.61; 'life': 0.64; 'kindly': 0.65; 'manner': 0.65; 'received:202': 0.66; 'cameron': 0.73; 'alternative.': 0.84 Date: Fri, 23 Dec 2011 12:21:40 +1100 From: Cameron Simpson To: Mac Smith Subject: Re: reading multiline output MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) References: Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1324603767 news.xs4all.nl 6942 [2001:888:2000:d::a6]:60325 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:17764 On 23Dec2011 06:37, Mac Smith 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 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 )