Makefile: How to assign a command's output and exit code to a variable?

后端 未结 2 1376
终归单人心
终归单人心 2021-01-15 05:55

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)



        
相关标签:
2条回答
  • 2021-01-15 06:18

    If you are going to use eval anyway, make it print things you can eval directly.

    $(eval $(shell echo OUTPUT_RC=`whoami`; echo $$?))
    OUTPUT=$(word 1,$(OUTPUT_RC))
    RC=$(word 2,$(OUTPUT_RC))
    
    0 讨论(0)
  • 2021-01-15 06:20

    GNU make offers the shell function, as in:

    OUTPUT=$(shell whoami)
    OUTPUT_RC=$(shell whoami; echo $$?)
    
    0 讨论(0)
提交回复
热议问题