In make, if I want to capture the output of a shell command, I do something like this
RESULT:=$(shell $(COMMAND))
If I want to check if a command executed properly, I do this
RETURN_CODE := $(shell $(COMMAND); echo $$?)
How can I do both simultaneously, i.e. execute the command once, store the output, but also check the return code?
EDIT Duplicate here although his solution is not pleasant: Makefile: Output and Exitcode to variable?
What about
OUTPUT_WITH_RC := $(shell $(COMMAND); echo $$?)
RETURN_CODE := $(lastword $(OUTPUT_WITH_RC))
OUTPUT := $(subst $(RETURN_CODE)QQQQ,,$(OUTPUT_WITH_RC)QQQQ)
If your command fails, it will probably write to stderr; you can use this to capture everything:
OUTPUT_WITH_RC := $(shell $(COMMAND) 2>$1; echo $$?)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With