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 30,  9:15am, Nikolai Weibull wrote:
} Subject: Re: Is it possible to capture stdout and stderr to separate varia
}
} On Thu, Mar 8, 2012 at 15:53, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
} > 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)"}")
} 
} That will, however, override the value of $status.

Indeed, good catch.  You need to pull $status inside the $(...) too
(in which case the trailing newline doesn't matter any more):

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



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