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 07, 2012 at 10:26:57AM +0100, Nikolai Weibull wrote:
> 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)"}")

Looks like it can be written as:

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

e.g.

% outs=("${(0)$({ out=$(fuser /usr/local/bin/zsh) } 2>&1; print $'\0'$out$'\0'$status)}")
/usr/local/bin/zsh: ee

  8013 14594
0

So the $'\n' and $'\0' are both reserved in the nested command
substitution since the whole substitution is in double quote. Not sure
if this is right here.

Thanks.



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