bash - How to capture stdout/stderr/time into variables in Zsh -
suppose following function exists.
action() { sleep 1 echo 'stdout' >&2 echo 'stderr' }
i want capture each of following items shell variables.
- stdout
- stderr
- execution time
the following code trick in bash.
unset stdout stderr time eval "$( { time action >&3 2>&4; } \ 2> >(time=$(cat); typeset -p time) \ 3> >(stdout=$(cat); typeset -p stdout) \ 4> >(stderr=$(cat); typeset -p stderr) )" echo "stdout: $stdout" echo "stderr: $stderr" echo "time: $time"
how can achieve in zsh?
Comments
Post a Comment