zsh-users
 help / color / mirror / code / Atom feed
From: Phil Pennock <zsh-workers+phil.pennock@spodhuis.org>
To: rahul <rahul2012@gmail.com>
Cc: zsh-users@zsh.org
Subject: Re: Capture stderr to variable without new process
Date: Mon, 21 Jan 2013 18:35:49 -0500	[thread overview]
Message-ID: <20130121233549.GA6494@redoubt.spodhuis.org> (raw)
In-Reply-To: <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


  reply	other threads:[~2013-01-21 23:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-21 20:11 rahul
2013-01-21 23:35 ` Phil Pennock [this message]
2013-01-23  7:36   ` Han Pingtian

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130121233549.GA6494@redoubt.spodhuis.org \
    --to=zsh-workers+phil.pennock@spodhuis.org \
    --cc=rahul2012@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).