Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!newsfeed.xs4all.nl!newsfeed2a.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'messages.': 0.05; 'output': 0.05; '"""': 0.07; 'attribute': 0.07; 'filenames': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'wrote': 0.14; '70,': 0.16; 'empty.': 0.16; 'error).': 0.16; 'grep': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.18; 'version.': 0.19; 'example': 0.22; 'header :User-Agent:1': 0.23; 'error': 0.23; 'closely': 0.24; 'replace': 0.24; 'stick': 0.24; 'source': 0.25; 'skip:" 30': 0.26; 'post': 0.26; 'header:X-Complaints-To:1': 0.27; "doesn't": 0.30; 'absolute': 0.30; 'errors': 0.30; 'along': 0.30; 'code': 0.31; "skip:' 10": 0.31; 'file': 0.32; '(most': 0.33; 'becomes': 0.33; "i'd": 0.34; 'subject:with': 0.35; 'created': 0.35; 'skip:s 30': 0.35; 'convert': 0.35; 'but': 0.35; 'possible': 0.36; 'to:addr :python-list': 0.38; 'recent': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'receive': 0.70; 'expose': 0.84; 'otten': 0.84; 'rick': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: piping with subprocess Date: Sat, 01 Feb 2014 18:32:14 +0100 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084bda1.dip0.t-ipconnect.de User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 66 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1391275915 news.xs4all.nl 2850 [2001:888:2000:d::a6]:38835 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:65229 Rick Dooling wrote: > On Saturday, February 1, 2014 6:54:09 AM UTC-6, Peter Otten wrote: >> Try to convert the example from the above page >> >> """ >> output=`dmesg | grep hda` >> # becomes >> p1 = Popen(["dmesg"], stdout=PIPE) >> p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE) >> p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits. >> output = p2.communicate()[0] >> """ >> >> to your usecase. Namely, replace >> >> ["dmesg"] --> ["textutil", "-convert", "html", infile, "-stdout"] >> ["grep", "hda"] --> ["pandoc", "-f", "html", "-t", "marktown", "-o", >> outfile] >> >> Don't forget to set >> >> infile = ... >> outfile = ... >> >> to filenames (with absolute paths, to avoid one source of error). >> If that doesn't work post the code you wrote along with the error >> messages. > > p1 = subprocess.Popen(["textutil", "-convert", "html", file], > stdout=subprocess.PIPE) > p2 = subprocess.check_call(["pandoc", "-f", > "html", "-t", "markdown", "-o", markdown_file], stdin=p1.stdout, > stdout=subprocess.PIPE) > p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits. > output = p2.communicate()[0] > > Errors > > Traceback (most recent call last): > File "/Users/me/Python/any2pandoc.py", line 70, in > convert_word_file(file, markdown_file) > File "/Users/me/Python/any2pandoc.py", line 59, in convert_word_file > output = p2.communicate()[0] > AttributeError: 'int' object has no attribute 'communicate' > > I get a markdown_file created but it's empty. Well, you replaced the Popen() from the example with a check_call() which uses a Popen instance internally, but does not expose it. I recommend that you stick as closely to the example as possible until you have a working baseline version. I'd try textutil = subprocess.Popen( ["textutil", "-convert", "html", file], stdout=subprocess.PIPE) pandoc = subprocess.Popen( ["pandoc", "-f", "html", "-t", "markdown", "-o", markdown_file], stdin=textutil.stdout) textutil.stdout.close() pandoc.communicate()