From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24435 invoked by alias); 7 Mar 2012 07:01:26 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 16851 Received: (qmail 6918 invoked from network); 7 Mar 2012 07:01:24 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <120306230111.ZM11639@torch.brasslantern.com> Date: Tue, 06 Mar 2012 23:01:11 -0800 In-reply-to: <1331054185.27052.19.camel@air.fifi.org> Comments: In reply to Philippe Troin "Re: Is it possible to capture stdout and stderr to separate variables in Zsh?" (Mar 6, 9:16am) References: <1331054185.27052.19.camel@air.fifi.org> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Zsh Users Subject: Re: Is it possible to capture stdout and stderr to separate variables in Zsh? MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Mar 6, 9:16am, Philippe Troin wrote: } } On Tue, 2012-03-06 at 09:09 +0100, Nikolai Weibull wrote: } > Is it possible to capture stdout and stderr to separate variables in Zsh? } } All I can think of is: } } coproc cat & } pid=$! } stdout="$( ( print "printed on stdout"; print -u 2 "printer on stderr" ) 2>&p )" } sleep 1 } kill "$pid" } stderr="$(cat <&p)" } } You'll notice the very ugly sleep+kill hack I had to use as I could not } find how you can close a coprocess's standard input cleanly. Removing } the sleep+kill makes the cat <&p hang forever. You need this: http://www.zsh.org/mla/users/2011/msg00095.html :-) } A completely different solution could involve the tcp zsh module which } can multiplex many streams with tcp_expect. But that's probably too } involved for this problem. You might also be able to do something with the zsh/zselect module, but just use a temp file. That solution works in bash, too.