From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18156 invoked by alias); 21 Jan 2013 23:36:08 -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: 17598 Received: (qmail 495 invoked from network); 21 Jan 2013 23:35:55 -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=-3.3 required=5.0 tests=BAYES_00,DKIM_ADSP_ALL, DKIM_SIGNED,RCVD_IN_DNSWL_MED,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at spodhuis.org does not designate permitted sender hosts) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=spodhuis.org; s=d201210; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=q0H1NhyEqc5ITjCqYw43ZeZ0MkEpxbdhM9InwsIvAdE=; b=MGK05m2TxDWAkxHDzSHwGDnPM6u7FWoQ08/noKPZgzZRQ2TYouokQYhOaoTuZl8CPKS/+tnhVmJxitB5rDszSXUYwcEssLVcr+djznYm2sUrmA3bSqJ4Xm9+FT3oRBiwpxnJOstqy1VJcaiYMACLxC9Wyfkx7qGS89GnyFjzzJA=; Date: Mon, 21 Jan 2013 18:35:49 -0500 From: Phil Pennock To: rahul Cc: zsh-users@zsh.org Subject: Re: Capture stderr to variable without new process Message-ID: <20130121233549.GA6494@redoubt.spodhuis.org> Mail-Followup-To: rahul , zsh-users@zsh.org References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On 2013-01-22 at 01:41 +0530, rahul wrote: > I guess the typical way would be: > > ERR=$(popd 2>&1) > > However, the command cannot run in a sub-shell as it would have no effect > in the current shell. > Is writing to a file the only way ? If the output can only be one line and you have an unbuffered cat(1) (-u option). % coproc cat -u [1] 6550 % popd 2>&p % read -p foo % echo $foo popd: directory stack empty % coproc - Otherwise, you need to script a cat-command which can exit on a sentinel line; I don't know of a way to close the coproc's stdin while leaving the coproc running to collect its output later. Perhaps someone else does? If you could send EOF on the coproc's stdin, then you could just use: popd_stderr="$(cat <&p)" after closing its stdin. -Phil