From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13894 invoked from network); 7 Jun 2006 14:58:17 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.3 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 7 Jun 2006 14:58:17 -0000 Received: (qmail 8868 invoked from network); 7 Jun 2006 14:58:10 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 7 Jun 2006 14:58:10 -0000 Received: (qmail 8635 invoked by alias); 7 Jun 2006 14:58:01 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10358 Received: (qmail 8626 invoked from network); 7 Jun 2006 14:58:01 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 7 Jun 2006 14:58:01 -0000 Received: (qmail 7674 invoked from network); 7 Jun 2006 14:58:00 -0000 Received: from cluster-d.mailcontrol.com (217.69.20.190) by a.mx.sunsite.dk with SMTP; 7 Jun 2006 14:57:58 -0000 Received: from cameurexb01.EUROPE.ROOT.PRI ([62.189.241.200]) by rly18d.srv.mailcontrol.com (MailControl) with ESMTP id k57EvbWk018350 for ; Wed, 7 Jun 2006 15:57:56 +0100 Received: from news01.csr.com ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.1830); Wed, 7 Jun 2006 15:55:57 +0100 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (8.13.4/8.13.4) with ESMTP id k57EuMjH032403 for ; Wed, 7 Jun 2006 15:56:22 +0100 Received: from csr.com (pws@localhost) by news01.csr.com (8.13.4/8.13.4/Submit) with ESMTP id k57EuMJA032400 for ; Wed, 7 Jun 2006 15:56:22 +0100 Message-Id: <200606071456.k57EuMJA032400@news01.csr.com> X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: zsh-users@sunsite.dk (Zsh users list) Subject: Re: Bi-directional pipe In-reply-to: <4486CBA2.9030501@yahoo.fr> References: <4486CBA2.9030501@yahoo.fr> Date: Wed, 07 Jun 2006 15:56:22 +0100 From: Peter Stephenson X-OriginalArrivalTime: 07 Jun 2006 14:55:57.0746 (UTC) FILETIME=[7BE11120:01C68A42] Content-Type: text/plain MIME-Version: 1.0 X-Scanned-By: MailControl A-07-00-10 (www.mailcontrol.com) on 10.68.0.128 Guillaume Chazarain wrote: > Is there a way to make a bi-directional pipe in zsh? > That is, something like: foo | bar doing implicitly bar | foo, so > foo stdin <- bar stdout and > foo stdout <- bar stdin With that sort of syntactically supported pipe, this depends on the OS. Some, like Solaris, have bidirectional pipes by default. On Solaris I can do: ( exec 0<&1; echo I said foo; read line; print $line >/dev/tty) | ( exec 1>&0; read line; print $line >/dev/tty; echo You said bar; ) I said foo You said bar On Fedora Core 5, however, this gives me I said foo zsh: write error: bad file descriptor If you are happy with something that looks a little bit like a biderectional pipe, but one of the processes is actually asynchronous, coprocesses are the simplest way of doing this (as mentioned in my reponse zsh-users/10354 yesterday). They contain a bidirectional pipe as standard. What's more, there's nothing to stop you from redirecting stdin and stdout in the main shell from and to the coprocess. The following seems to work fine: ( coproc { read line print Coproc got $line >&2 print Reply } exec 1>&p 0<&p print Request read line print Main shell got $line >&2 ) producing: Coproc got Request Main shell got Reply The only point of the business with fd 2 is to confirm that it's working. In summary, you can get what you want with: ( coproc { } exec 1>&p 0<&p ) You don't even need the subshell, necessary: that's just there to protect the interactive environment from the redirection. -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php