Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!news2.arglkargh.de!news.wiretrip.org!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'exception,': 0.07; 'see:': 0.07; 'python': 0.07; 'exception.': 0.09; 'tuple': 0.09; 'pm,': 0.11; 'subject:error': 0.12; 'wrote:': 0.14; "b'')": 0.16; 'benjamin': 0.16; 'instantiate': 0.16; 'osx': 0.16; 'posix': 0.16; 'shells': 0.16; 'subject:command': 0.16; 'subject:subprocess': 0.16; 'permission': 0.16; 'code.': 0.18; 'object,': 0.19; 'simpler': 0.19; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.20; 'code,': 0.20; 'cheers,': 0.20; 'code': 0.22; 'header:In-Reply- To:1': 0.22; 'cc:addr:python-list': 0.22; 'parse': 0.23; 'received:209.85.214.174': 0.23; 'received:mail- iw0-f174.google.com': 0.23; 'skip:( 30': 0.24; 'chris': 0.27; 'work.': 0.27; 'message-id:@mail.gmail.com': 0.28; 'raise': 0.29; 'string': 0.29; 'error': 0.29; 'sat,': 0.29; 'exit': 0.29; 'cc:addr:python.org': 0.31; 'however,': 0.31; 'url:library': 0.31; 'url:docs': 0.33; 'using': 0.34; 'fails': 0.35; 'message,': 0.37; 'received:209.85': 0.37; 'url:python': 0.37; 'apr': 0.38; 'received:google.com': 0.38; 'url:org': 0.38; 'to.': 0.39; 'received:209.85.214': 0.39; 'received:209': 0.39; 'how': 0.39; 'header:Received:5': 0.40; '2011': 0.62; 'here': 0.65; 'cause': 0.65; 'response.': 0.67; 'subject:Get': 0.74; '11:50': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=domainkey-signature:mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:cc:content-type; bh=KGE08FSSs29vROJP89Sc/vVz+IEPH1qyoz//Mkb0rwo=; b=KiD6sAhsa/sjitpTBOcjEdj2jZ9VrrWccMTI1JbrsRtStFs6uiDblHHsCG1u5EGUox Zq1kYAXJvgY0ZRlm717XhS9KfdX6VDpWv2a9SfUi3Tf+5ydoGrEDXAp9u/4ZSA5yQWKC W2C7vsLQLjVQfqYzXQ37rfFm93C+NCOu09A9g= DomainKey-Signature: a=rsa-sha1; c=nofws; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:cc:content-type; b=JttAlpszCYYBILl22Vnk5RXKNOvsLOaI1kS18u2wUIuc3h5WvUv/dBF+EQkB7+RBrJ Kvu1tvlxNsrd2qM6Qba3LAkTIGJbbhxl7FdJVeg0IBAOp3NmXQD59op2oRc5MFe6bTzl ma8wApitIQ4pxjdoHaAdEUJFK4ugL9bT5DxLU= MIME-Version: 1.0 Sender: chris@rebertia.com In-Reply-To: References: <7d8d2159-20ac-4bdc-afa8-f28b8ee29394@d26g2000prn.googlegroups.com> Date: Sat, 2 Apr 2011 21:10:21 -0700 X-Google-Sender-Auth: vGkUk-6DPLnu3EkRSQGANaPIIL4 Subject: Re: Get subprocess error output from shell command From: Chris Rebert Cc: python-list@python.org Content-Type: text/plain; charset=UTF-8 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: 27 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1301803824 news.xs4all.nl 41114 [::ffff:82.94.164.166]:59922 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:2496 On Sat, Apr 2, 2011 at 9:03 PM, Benjamin Kaplan wrote: > On Sat, Apr 2, 2011 at 11:50 PM, Gnarlodious wrote: >> I get it, you instantiate an object, call a method and get a tuple in >> response. However, here is what I see: >> >>>>> process.communicate() >> (b'~/Library/Preferences/iCab/iCab 4 Bookmarks: Permission denied\n', >> b'') >> >> So all I get is the string and no error message, which is the same >> thing I get with the simpler subprocess.call(). I can parse out the >> error out and handle it if I need to. Is this a failing in the OSX >> plutil tool? > > Were you expecting a Python error? That's not how POSIX shells work. A > process that fails just gives you a non-zero return code, not an > exception. You can call process.poll() to get the return code. However, using subprocess.check_call() or subprocess.check_output() will cause a non-zero exit code to raise a Python exception, CalledProcessError. http://docs.python.org/library/subprocess.html#subprocess.check_call http://docs.python.org/library/subprocess.html#subprocess.check_output Cheers, Chris