on-internet
← Community

Pipe output and capture exit status in Bash

Stack Overflow ·

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=$? The problem is that the variable ST captures the exit status of tee and not of command. How can I solve this? Note that command is long running and redirecting the output to a file to view it later is not a good solution for me.

Comments

Sign in or sign up to comment and upvote.

No comments yet.