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 Mar 7, 10:26am, Nikolai Weibull wrote:
}
} outs=("${(@0):-"$({ out=$(x) } 2>&1; print $'\0'$out$'\0'$status)"}")

That's nice.  You can solve the problem that Philippe mentioned with
loss of trailing newlines, by embedding one NUL in $out like so:

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

Then I sort of like the idea of making it into an associative array:

typeset -A outs
outs=(STDERR "${(@0):-"$({ out="$(x; print -n $'\0')" } 2>&1;
                    print $'\0'STDOUT$'\0'${out}STATUS$'\0'$status)"}")
print -r $outs[STDOUT]



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