Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.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.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subprocess': 0.09; 'pm,': 0.11; 'subject:error': 0.12; 'error:': 0.14; 'wrote:': 0.14; '#the': 0.16; 'confusing.': 0.16; 'pipe,': 0.16; 'popen,': 0.16; 'stderr': 0.16; 'stdout': 0.16; 'subject:command': 0.16; 'subject:subprocess': 0.16; 'capture': 0.16; 'permission': 0.16; 'shell': 0.19; 'command': 0.19; 'header:In-Reply-To:1': 0.22; 'doc': 0.23; 'says': 0.25; "i'm": 0.26; 'putting': 0.26; 'object': 0.27; 'message-id:@mail.gmail.com': 0.28; 'error': 0.29; 'sat,': 0.29; 'skip:" 30': 0.29; "skip:' 30": 0.29; 'list': 0.30; 'do.': 0.31; 'it.': 0.31; 'url:library': 0.31; 'import': 0.32; 'to:addr :python-list': 0.32; 'url:docs': 0.33; 'bit': 0.33; 'using': 0.34; 'communicate': 0.35; 'like:': 0.35; 'running': 0.36; 'getting': 0.36; 'url:python': 0.37; 'apr': 0.38; 'received:google.com': 0.38; 'but': 0.38; 'url:org': 0.38; 'docs': 0.39; 'to:addr:python.org': 0.39; 'how': 0.39; 'would': 0.40; '2011': 0.62; 'url:3': 0.68; 'url:0': 0.69; 'subject:Get': 0.74; 'received:129': 0.84; 'skip:~ 30': 0.84 MIME-Version: 1.0 In-Reply-To: References: Date: Sat, 2 Apr 2011 23:25:58 -0400 Subject: Re: Get subprocess error output from shell command From: Benjamin Kaplan To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-Junkmail-Status: score=10/49, host=mpv1.tis.cwru.edu X-Junkmail-Signature-Raw: score=unknown, refid=str=0001.0A020208.4D97E8C7.008F,ss=1,fgs=0, ip=74.125.82.182, so=2010-12-23 16:51:53, dmn=2009-09-10 00:05:08, mode=single engine X-Junkmail-IWF: false 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: 34 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1301801169 news.xs4all.nl 41117 [::ffff:82.94.164.166]:42909 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:2488 On Sat, Apr 2, 2011 at 11:07 PM, Gnarlodious 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()