Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Capture stderr to variable without new process
- X-seq: zsh-users 17598
- From: Phil Pennock <zsh-workers+phil.pennock@xxxxxxxxxxxx>
- To: rahul <rahul2012@xxxxxxxxx>
- Subject: Re: Capture stderr to variable without new process
- Date: Mon, 21 Jan 2013 18:35:49 -0500
- Cc: zsh-users@xxxxxxx
- 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=;
- In-reply-to: <CACQNQ9Mz1hX4kYs+MnYmt8p+_LvBOmg1s6tdYogALXj+tme6Gw@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mail-followup-to: rahul <rahul2012@xxxxxxxxx>, zsh-users@xxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CACQNQ9Mz1hX4kYs+MnYmt8p+_LvBOmg1s6tdYogALXj+tme6Gw@mail.gmail.com>
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author