Is this even possible?
I'd like to run a command but capture its stdout and stderr as separate variables. Currently I'm using set -l var (cmd)
, which leaves stderr untouched. I can do set -l var (cmd ^&1)
which will merge stdout and stderr into var, but then I can't easily separate them again.
Is there any way to get var and var_err to hold stdout and stderr from cmd?
begin; cmd ^|read -z err; end |read -z out
From fish-shell/fish-shell #2463,
An issue in your fish example is that it redirects [stdout] of both [cmd] and [read], so if the latter prints anything, it'll be carried through the pipe.
But I don't think read should ever print anything (especially to stdout) in the normal case, so this should be fine.
Edit: If the exact semantics of set var (cmd)
are needed, that can be achieved using set var (printf '%s' $out)
and set var_err (printf '%s' $err)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다