From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1252 invoked by alias); 1 Sep 2012 12:09:51 -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: 17219 Received: (qmail 8836 invoked from network); 1 Sep 2012 12:09:49 -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=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at linux.vnet.ibm.com does not designate permitted sender hosts) Date: Sat, 1 Sep 2012 19:59:37 +0800 From: Han Pingtian To: zsh-users@zsh.org Subject: Re: Is it possible to capture stdout and stderr to separate variables in Zsh? Message-ID: <20120901115937.GC1777@localhost.localdomain> References: <1331054185.27052.19.camel@air.fifi.org> <120306230111.ZM11639@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <120306230111.ZM11639@torch.brasslantern.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12090111-9360-0000-0000-00000A14B26C On Tue, Mar 06, 2012 at 11:01:11PM -0800, Bart Schaefer wrote: > 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 :-) > Hi, I'm using zsh 5.0, but looks like still cannot close the prior coproc with "coproc exit": % coproc while read line;do print -r -- "$line:u";done [1] 31518 % coproc exit [2] 31519 % [2] + done exit % jobs [1] + running while read line; do; print -r -- "$line:u"; done % or I'm missing something here? Thanks.