From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25563 invoked by alias); 8 Mar 2012 04:57:17 -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: 16872 Received: (qmail 91 invoked from network); 8 Mar 2012 04:57:15 -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: <120307205659.ZM13143@torch.brasslantern.com> Date: Wed, 07 Mar 2012 20:56:59 -0800 In-reply-to: <1331149023.9089.8.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 7, 11:37am) References: <1331054185.27052.19.camel@air.fifi.org> <120306230111.ZM11639@torch.brasslantern.com> <1331149023.9089.8.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 7, 11:37am, Philippe Troin wrote: } } > } coproc cat & } > } pid=$! } > } stdout="$( ( print "printed on stdout"; print -u 2 "printer on stderr" ) 2>&p )" } > } sleep 1 } > } kill "$pid" } > } stderr="$(cat <&p)" } > } > You need this: http://www.zsh.org/mla/users/2011/msg00095.html :-) } } I didn't see anything in there that could suppress the sleep+kill. Look at the part subtitled "Where might I go wrong with coproc?" ... it doesn't answer the whole problem, but it tells you how to cleanly close the descriptors. The full solution is more like: coproc cat & exec {p}<&p # Copy the <&p descriptor stdout="$( ( print "printed on stdout"; print -u 2 "printed on stderr") 2>&p )" coproc exit # Close both <&p and >&p descriptors stderr="$(cat <&$p)" # Read from copy descriptor exec {p}<&- # Close the copy (optional) I also dug this up: http://www.zsh.org/mla/workers/2000/msg03684.html but that predates the fancy {p}<&p syntax. } I like Nikolai's solution best, except that it's somewhat cryptic Yeah, I may have some thoughts on that one, too.