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


Groups > comp.lang.python > #2488

Re: Get subprocess error output from shell command

References <dc8e1dcd-303c-4e07-bdda-1b12277976f0@f31g2000pri.googlegroups.com>
Date 2011-04-02 23:25 -0400
Subject Re: Get subprocess error output from shell command
From Benjamin Kaplan <benjamin.kaplan@case.edu>
Newsgroups comp.lang.python
Message-ID <mailman.149.1301801169.2990.python-list@python.org> (permalink)

Show all headers | View raw


On Sat, Apr 2, 2011 at 11:07 PM, Gnarlodious <gnarlodious@gmail.com> wrote:
> I'm running a shell command like:
> plutil -convert xml1 "~/Library/Preferences/iCab/iCab 4 Bookmarks"
>
> Getting error:
> ~/Library/Preferences/iCab/iCab 4 Bookmarks: Permission denied
>
> How would I capture this error using a method of subprocess?
>
> I read the doc at
> http://docs.python.org/release/3.0.1/library/subprocess.html
>
> but confess I don't understand it.
>
> -- Gnarlie
> http://Gnarlodious.com/
> --

Yeah, the subprocess docs are a bit confusing. Here's what you need to do.



from subprocess import Popen, PIPE

#create a Popen object
#note that I'm putting the command in a list
#the stdout=PIPE thing says I want to capture it
process = Popen( ['plutil', '-convert', 'xml1',
'~/Library/Preferences/iCab/iCab 4 Bookmarks'], stdout = PIPE, stderr
= PIPE)

#then, you communicate with the process

outdata, errdata = process.communicate()

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