Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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.023 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'output': 0.05; 'subject:skip:s 10': 0.07; 'output,': 0.09; 'subject:instance': 0.09; '11:32': 0.16; 'block.': 0.16; 'forty': 0.16; 'stderr': 0.16; 'stdout': 0.16; 'wrote:': 0.18; 'aug': 0.22; 'separate': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'handling': 0.26; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'tim': 0.29; 'code': 0.31; 'fri,': 0.33; 'could': 0.34; 'display': 0.35; 'johnson': 0.35; 'but': 0.35; 'skip:s 60': 0.36; 'charset :us-ascii': 0.36; 'to:addr:python-list': 0.38; 'fact': 0.38; 'to:addr:python.org': 0.39; 'manually': 0.60; 'break': 0.61; 'full': 0.61; 'content-disposition:inline': 0.62; '30,': 0.65; 'hill': 0.95; '2013': 0.98 Date: Fri, 30 Aug 2013 10:43:57 -0800 From: Tim Johnson To: "python-list (General)" Subject: Re: subprocess.Popen instance hangs Mail-Followup-To: "python-list (General)" References: <20130829183418.GE414@mail.akwebsoft.com> <20130830153229.GC400@mail.akwebsoft.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i Organization: AkWebsoft X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 1377888246 news.xs4all.nl 15951 [2001:888:2000:d::a6]:57624 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:53311 * Jerry Hill [130830 07:48]: > On Fri, Aug 30, 2013 at 11:32 AM, Tim Johnson wrote: > > The objective is to display all output, but to also separate error > > messages from normal output. > > I still think you want to use communicate(). Like this: > > p = subprocess.Popen(args,stderr=subprocess.PIPE,stdout=subprocess.PIPE) > output, err = p.communicate() > > That's it. No need for a loop, or manually handling the fact that > stderr and/or stdout could end up with a full buffer and start to > block. The following code : p = subprocess.Popen(args,stderr=subprocess.PIPE,stdout=subprocess.PIPE) errmsg,output = p.communicate() ... Hangs this code : p = subprocess.Popen(args,stderr=subprocess.PIPE,stdout=subprocess.PIPE) while 1 : output = p.stdout.read() if output : print(output) else : break ... works -- Tim tim at tee jay forty nine dot com or akwebsoft dot com http://www.akwebsoft.com