Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!news.tele.dk!news.tele.dk!small.news.tele.dk!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.026 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'output': 0.05; 'true,': 0.05; 'subject:Python': 0.06; 'subject:using': 0.09; 'terminates': 0.09; '"r")': 0.16; 'accepts': 0.16; 'blocks': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'stdout': 0.16; 'wrote:': 0.18; 'separate': 0.22; 'shell': 0.22; 'header:User-Agent:1': 0.23; 'header:In-Reply-To:1': 0.27; 'pipe': 0.31; 'file': 0.32; 'open': 0.33; 'reader': 0.33; "can't": 0.35; 'add': 0.35; 'thanks': 0.36; 'skip:o 20': 0.38; 'handle': 0.38; 'to:addr:python-list': 0.38; 'delete': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'read': 0.60; "you're": 0.61; 'first': 0.61; 'back': 0.62; 'close': 0.67; 'header:Reply-To:1': 0.67; 'reply- to:no real name:2**0': 0.71; 'end.': 0.84; 'process...': 0.84; 'reply-to:addr:python.org': 0.84; 'opens': 0.91 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=KrN0hwmN c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=K2DDQYBT4xIA:10 a=zc0myEFsKt8A:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=5F5fH2KFBC4A:10 a=h28_mT_9bvsQnLVmp3sA:9 a=wPNLvfGTeEIA:10 X-AUTH: mrabarnett:2500 Date: Mon, 05 Aug 2013 20:45:05 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Simulate `bash` behaviour using Python and named pipes. References: <7f5c60c4-50c7-4a93-af22-5c8549f87461@googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org 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: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1375731902 news.xs4all.nl 15999 [2001:888:2000:d::a6]:39906 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:51976 On 05/08/2013 17:54, Luca Cerone wrote: > Thanks this works (if you add shell=True in Popen). > If I don't want to use shell = True, how can I redirect the stdout to named_pipe? Popen accepts an open file handle for stdout, which I can't open for writing because that blocks the process... > You're back to using separate threads for the reader and the writer. The one that opens the pipe first will block until the other one opens the other end. >> >> >> os.mkfifo("named_pipe", 0777) >> >> ls_process = subprocess.Popen("ls -lah > named_pipe") >> >> pipe = open("named_pipe", "r") >> >> # Read the output of the subprocess from the pipe. >> >> >> >> When the subprocess terminates (look at the docs for Popen objects), >> >> close and delete the fifo. >