2

I have the following bash code to capture the result of a build while printing the output to the screen and provide parsing of the build results.

output=$(unbuffer cmake ... | tee /dev/tty)
parseErrors ${output}

parseErrors does what it sounds like. It parses the output for anything that looks like an error. I can exit there, but would rather do it after the function call. How do I get the return status from the cmake build passed to the unbuffer command? I have tried using PIPESTATUS[0], but I think that is returning the value from unbuffer itself.

2
  • I'm not able to understand what you want to achieve. Maybe you want to get the errors produced by unbuffer cmake ... and pass them to parseErrors function? Sep 26, 2022 at 22:24
  • @EdgarMagallon, the errors produced by cmake that is wrapped by the unbuffer call.
    – Coder909
    Sep 27, 2022 at 18:38

1 Answer 1

2

Assuming you want to have access to the return code from cmake after the 2 lines, you can do

output=$(unbuffer cmake ... | tee /dev/tty; exit "${PIPESTATUS[0]}")
rc=$?
parseErrors ${output}
exit "$rc"

The use of PIPESTATUS has to be in the $() subshell. If you just want to add the return code to the output, replace the exit by an echo.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .