Reputation: 783
python ./folder/script.py ; result=$$?; echo "$$result"
the echo result is 0 or 1
How can i set the value of $$result in a variable to use in the following if/else:
My Make file Command:
deploy/run:
$(shell python ./folder/script.py)
ifeq ($(.SHELLSTATUS),0)
export TF_VAR_DB_NAME='some_db'
else
export TF_VAR_DB_NAME='other_db'
endif
My script.py basics is:
class TaskChecker(object):
@staticmethod
def run():
matches = True
if matches:
sys.exit(1)
else:
sys.exit(0)
if __name__ == "__main__":
TaskChecker.run()
GNU Make 3.81
Upvotes: 0
Views: 548
Reputation: 54698
If you change your Python code to print to stdout, you can suck up the text directly:
result := $(shell python ./folder/script.py)
If you really need just the exit code, this should work:
$(shell python ./folder/script.py)
ifeq ($(.SHELLSTATUS),1)
echo "YEY"
else
echo "OHNO"
endif
GNU Make 3.81
Update
Here's an example showing that this works:
C:\tmp>cat Makefile
$(shell python -c "import sys\; sys.exit(1)")
ifeq ($(.SHELLSTATUS), 0)
export LEFT = 123
else
export LEFT = 456
endif
all:
python -c "import os; print(os.environ['LEFT'])"
C:\tmp>make
python -c "import os; print(os.environ['LEFT'])"
456
C:\tmp>
Upvotes: 1