Pipe output and capture exit status in Bash

后端 未结 15 1317
盖世英雄少女心
盖世英雄少女心 2020-11-22 08:07

I want to execute a long running command in Bash, and both capture its exit status, and tee its output.

So I do this:

command | tee out.txt
ST=$?
         


        
15条回答
  •  臣服心动
    2020-11-22 08:37

    Dumb solution: Connecting them through a named pipe (mkfifo). Then the command can be run second.

     mkfifo pipe
     tee out.txt < pipe &
     command > pipe
     echo $?
    

提交回复
热议问题