Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #2496

Re: Get subprocess error output from shell command

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 <chris@rebertia.com>
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 <AANLkTikM5wta6mpDFivz9+4KMh1ztMNUVCUv+kpNXswT@mail.gmail.com>
References <dc8e1dcd-303c-4e07-bdda-1b12277976f0@f31g2000pri.googlegroups.com> <mailman.150.1301801357.2990.python-list@python.org> <7d8d2159-20ac-4bdc-afa8-f28b8ee29394@d26g2000prn.googlegroups.com> <AANLkTikM5wta6mpDFivz9+4KMh1ztMNUVCUv+kpNXswT@mail.gmail.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 <clp2@rebertia.com>
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 <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.152.1301803824.2990.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Sat, Apr 2, 2011 at 9:03 PM, Benjamin Kaplan
<benjamin.kaplan@case.edu> wrote:
> On Sat, Apr 2, 2011 at 11:50 PM, Gnarlodious <gnarlodious@gmail.com> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Get subprocess error output from shell command Gnarlodious <gnarlodious@gmail.com> - 2011-04-02 20:07 -0700
  Re: Get subprocess error output from shell command Benjamin Kaplan <benjamin.kaplan@case.edu> - 2011-04-02 23:25 -0400
    Re: Get subprocess error output from shell command Gnarlodious <gnarlodious@gmail.com> - 2011-04-02 20:36 -0700
  Re: Get subprocess error output from shell command Chris Rebert <clp2@rebertia.com> - 2011-04-02 20:29 -0700
    Re: Get subprocess error output from shell command Gnarlodious <gnarlodious@gmail.com> - 2011-04-02 20:50 -0700
      Re: Get subprocess error output from shell command Benjamin Kaplan <benjamin.kaplan@case.edu> - 2011-04-03 00:03 -0400
      Re: Get subprocess error output from shell command Chris Rebert <clp2@rebertia.com> - 2011-04-02 21:10 -0700
    Re: Get subprocess error output from shell command Gnarlodious <gnarlodious@gmail.com> - 2011-04-02 21:00 -0700
      Re: Get subprocess error output from shell command Chris Rebert <clp2@rebertia.com> - 2011-04-02 21:14 -0700

csiph-web