Capture stdout and stderr as separate variables in fish shell

Soumya

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?

Soumya
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] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Disowned command with redirected STDOUT/STDERR still sending output to shell

분류에서Dev

管道STDERR与STDOUT

분류에서Dev

Capture :: Tiny를 얻는 방법 : 실패시 stderr 및 stdout을 인쇄하려면?

분류에서Dev

배관 STDERR 대 STDOUT

분류에서Dev

배관 STDERR 대 STDOUT

분류에서Dev

How to expand aliases in fish shell?

분류에서Dev

Ruby Gem Collapse Fish Shell

분류에서Dev

stdout을 stderr로 바꾸기

분류에서Dev

How to send stderr to stdout with a pipe to another command?

분류에서Dev

fish shell: "shopt -s dotglob" analog

분류에서Dev

Set bash as default shell with option to enter into fish

분류에서Dev

stdout 및 stderr을 파일로, stderr을 stdout으로 리디렉션

분류에서Dev

How to redirect stderr and stdout to different files and also display in terminal?

분류에서Dev

Logging in C printing to both stdout and stderr without duplicates

분류에서Dev

lftp, stdout, stderr 및 SAP exec_protocol

분류에서Dev

echo 또는 print / dev / stdin / dev / stdout / dev / stderr

분류에서Dev

systemd 서비스의 stdout / stderr보기

분류에서Dev

QTextEdit 위젯에서 stdout, stderr 복제

분류에서Dev

PowerShell 결합 및 로그 Stderr / Stdout

분류에서Dev

stdout을 tcsh의 stderr로 리디렉션

분류에서Dev

Perl: Getting STDERR of system call, separately from STDOUT

분류에서Dev

STDIN, STDOUT, STDERR 및 반환 값 정보

분류에서Dev

Redirect stdout and stderr when ampersand(&) is used between commands in bash

분류에서Dev

How can I convert to uppercase stderr output but not stdout?

분류에서Dev

What is a good way to get back to the command prompt discarding STDOUT and STDERR

분류에서Dev

How can I view stdout/stderr of a startup application?

분류에서Dev

GNU 병렬 정렬 stdout 및 stderr

분류에서Dev

파일에 stderr 및 stdout 추가

분류에서Dev

Bash 스크립트 stderr 및 stdout

Related 관련 기사

  1. 1

    Disowned command with redirected STDOUT/STDERR still sending output to shell

  2. 2

    管道STDERR与STDOUT

  3. 3

    Capture :: Tiny를 얻는 방법 : 실패시 stderr 및 stdout을 인쇄하려면?

  4. 4

    배관 STDERR 대 STDOUT

  5. 5

    배관 STDERR 대 STDOUT

  6. 6

    How to expand aliases in fish shell?

  7. 7

    Ruby Gem Collapse Fish Shell

  8. 8

    stdout을 stderr로 바꾸기

  9. 9

    How to send stderr to stdout with a pipe to another command?

  10. 10

    fish shell: "shopt -s dotglob" analog

  11. 11

    Set bash as default shell with option to enter into fish

  12. 12

    stdout 및 stderr을 파일로, stderr을 stdout으로 리디렉션

  13. 13

    How to redirect stderr and stdout to different files and also display in terminal?

  14. 14

    Logging in C printing to both stdout and stderr without duplicates

  15. 15

    lftp, stdout, stderr 및 SAP exec_protocol

  16. 16

    echo 또는 print / dev / stdin / dev / stdout / dev / stderr

  17. 17

    systemd 서비스의 stdout / stderr보기

  18. 18

    QTextEdit 위젯에서 stdout, stderr 복제

  19. 19

    PowerShell 결합 및 로그 Stderr / Stdout

  20. 20

    stdout을 tcsh의 stderr로 리디렉션

  21. 21

    Perl: Getting STDERR of system call, separately from STDOUT

  22. 22

    STDIN, STDOUT, STDERR 및 반환 값 정보

  23. 23

    Redirect stdout and stderr when ampersand(&) is used between commands in bash

  24. 24

    How can I convert to uppercase stderr output but not stdout?

  25. 25

    What is a good way to get back to the command prompt discarding STDOUT and STDERR

  26. 26

    How can I view stdout/stderr of a startup application?

  27. 27

    GNU 병렬 정렬 stdout 및 stderr

  28. 28

    파일에 stderr 및 stdout 추가

  29. 29

    Bash 스크립트 stderr 및 stdout

뜨겁다태그

보관