Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Is it possible to capture stdout and stderr to separate variables in Zsh?



On Wed, Mar 7, 2012 at 08:01, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> 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?

> You might also be able to do something with the zsh/zselect module, but
> just use a temp file.  That solution works in bash, too.

Invoking two additional commands (mktemp and rm) is prohibitively
expensive on Cygwin for my use case.  I used the following solution
instead:

outs=("${(@0):-"$({ out=$(x) } 2>&1; print $'\0'$out$'\0'$status)"}")

The indexes into outs are reversed in regard to the file descriptors,
but that’s not a big deal.



Messages sorted by: Reverse Date, Date, Thread, Author