2

I have this:

node ${SUMAN_RUNNABLE} | tee -a run.sh.log
EXIT_CODE=$?;

but it looks like the exit code is always 0 because tee is providing the code not the node executable.

Is there a way to capture the exit code from the node executable in such a scenario?

0

1 Answer 1

2

From https://stackoverflow.com/a/1221870/5020949:

There is an internal Bash variable called $PIPESTATUS; it’s an array that holds the exit status of each command in your last foreground pipeline of commands.

<command> | tee out.txt ; test ${PIPESTATUS[0]} -eq 0

Or another alternative which also works with other shells (like zsh) would be to enable pipefail:

set -o pipefail
...

The first option does not work with zsh due to a little bit different syntax.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.