2

I am searching for a way to get the output and the exit code of a command to variables in a makefile.

Basicly I want this: (bash)

output=$(whoami)
returnval=$?
echo "OUT:"
echo $output
echo "RET:"
echo $returnval

to be in a makefile

note: should work in a rule section

Thanks

EDIT: SOLVED

$(eval OUTPUT_RC="$(shell whoami;echo $$?)")
$(eval OUTPUT="$(shell echo $(OUTPUT_RC) | sed -e "s/^\(.*\)\(.\{2\}\)$$/\1/")")
$(eval RC="$(shell echo $(OUTPUT_RC) | sed -e "s/^.*\(.\)$$/\1/")")
echo $(OUTPUT)
echo $(RC)
4

2 回答 2

0

如果你无论如何都要使用eval,让它打印你可以eval直接打印的东西。

$(eval $(shell echo OUTPUT_RC=`whoami`; echo $$?))
OUTPUT=$(word 1,$(OUTPUT_RC))
RC=$(word 2,$(OUTPUT_RC))
于 2017-12-12T08:49:03.567 回答
-1

GNU make 提供了这个shell功能,如:

OUTPUT=$(shell whoami)
OUTPUT_RC=$(shell whoami; echo $$?)
于 2012-06-22T13:42:53.877 回答