Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed20.multikabel.net!amsnews11.chello.com!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'script,': 0.07; '21,': 0.09; 'file-like': 0.09; 'subprocess': 0.09; 'tkinter': 0.09; 'output': 0.10; 'cc:addr:python-list': 0.15; 'behavior?': 0.16; 'runs.': 0.16; 'subject:subprocess': 0.16; 'wrote:': 0.16; 'once,': 0.18; 'jan': 0.19; 'cheers,': 0.20; 'trying': 0.20; 'cc:no real name:2**0': 0.21; 'result.': 0.21; 'header:In-Reply- To:1': 0.22; 'runs': 0.23; 'cc:2**0': 0.25; 'sat,': 0.25; 'pm,': 0.26; 'received:209.85.220': 0.27; 'message-id:@mail.gmail.com': 0.28; 'cc:addr:python.org': 0.29; 'yes.': 0.30; 'chris': 0.30; 'url:library': 0.30; 'object': 0.33; 'window': 0.35; 'url:python': 0.36; 'run': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.38; 'url:docs': 0.39; 'url:org': 0.39; 'received:209': 0.39; 'expected': 0.39; 'subject:: ': 0.39; 'skip:\xc2 10': 0.74; '9:45': 0.84; 'sender:addr:chris': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc :x-gm-message-state:content-type:content-transfer-encoding; bh=XiFE0QtFwb2MMsm8+S3Qfrhws9dOKoaYZ8kW1vQGll0=; b=Iu7Ry9mvrh9fRpBfvIOtxQKtclxDiUXxxeiXIHv6NRYA9/X9ytt/kZ2bc3qVZE+uxM Uoign8tUWFu4ItqmrNDpTC3/BU6eBBkUTiY5/nwK9ulQb50oSHFwAWdSqr8za3NLRaPw xJ86xJfq7yny1lg3oDmMn9uEi7fjLEjZeUqsc= MIME-Version: 1.0 Sender: chris@rebertia.com In-Reply-To: References: Date: Sat, 21 Jan 2012 23:27:54 -0800 X-Google-Sender-Auth: mPoUerR66ZpdaopQ28vfL93fYno Subject: Re: bufsize in subprocess From: Chris Rebert To: yves@zioup.com X-Gm-Message-State: ALoCoQleOWwDe5bqKoMYsM+Sk1R1KNbWx/p/VIabH/M40H5871c/YO+mzALiKWiu5gnU3zfdca+b Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1327217278 news.xs4all.nl 6885 [2001:888:2000:d::a6]:35845 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19207 On Sat, Jan 21, 2012 at 9:45 PM, wrote: > Is this the expected behavior? Yes. `.read()` [with no argument] on a file-like object reads until EOF. See http://docs.python.org/library/stdtypes.html#file.read > When I run this script, it reads only once, but I expected once per line > with bufsize=3D1. You want proc.stdout.readline(). http://docs.python.org/library/stdtypes.html#file.readline > What I am trying to do is display the output of a slow process in a tkint= er > window as it runs. Right now, the process runs to completion, then displa= y > the result. > > =C2=A0 =C2=A0import subprocess > > =C2=A0 =C2=A0com =3D ['/bin/ls', '-l', '/usr/bin'] > =C2=A0 =C2=A0with subprocess.Popen(com, bufsize=3D1, stdout=3Dsubprocess.= PIPE, > stderr=3Dsubprocess.STDOUT) as proc: > =C2=A0 =C2=A0 =C2=A0 =C2=A0print('out: ' + str(proc.stdout.read(), 'utf8'= )) Cheers, Chris