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

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 2011-04-02 21:10 -0700
Subject Re: Get subprocess error output from shell command
From Chris Rebert <clp2@rebertia.com>
Newsgroups comp.lang.python
Message-ID <mailman.152.1301803824.2990.python-list@python.org> (permalink)

Show all headers | 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