From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23947 invoked by alias); 8 Mar 2012 14:54:13 -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: 16873 Received: (qmail 23967 invoked from network); 8 Mar 2012 14:54:11 -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: <120308065332.ZM14313@torch.brasslantern.com> Date: Thu, 08 Mar 2012 06:53:32 -0800 In-reply-to: Comments: In reply to Nikolai Weibull "Re: Is it possible to capture stdout and stderr to separate variables in Zsh?" (Mar 7, 10:26am) References: <1331054185.27052.19.camel@air.fifi.org> <120306230111.ZM11639@torch.brasslantern.com> 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, 10:26am, Nikolai Weibull wrote: } } outs=("${(@0):-"$({ out=$(x) } 2>&1; print $'\0'$out$'\0'$status)"}") That's nice. You can solve the problem that Philippe mentioned with loss of trailing newlines, by embedding one NUL in $out like so: outs=("${(@0):-"$({ out="$(x; print -n $'\0')" } 2>&1; print $'\0'$out$status)"}") Then I sort of like the idea of making it into an associative array: typeset -A outs outs=(STDERR "${(@0):-"$({ out="$(x; print -n $'\0')" } 2>&1; print $'\0'STDOUT$'\0'${out}STATUS$'\0'$status)"}") print -r $outs[STDOUT]