Can somebody help me to find a way to capture the return value from a python script in Makefile.I have a scenario where the source code is getting build through the Makefile and it should throw a build error when python script reruns a failure.
myMakefile.mak
python mySample.py <arg1> <arg2> // Invoking python script here, How to get script's return value?
mySample.py
SUCCESS 0
FAIL 1
if(true)
exit(SUCCESS)
else:
exit(FAIL)
Thanks in advance.
If your python script exits with a non-zero code, make will detect this and tell you that an error occurred. So you don't need to do anything more.
Example, if I have a program foo.py that does this:
print 'running foo'
exit(1)
And a Makefile like this:
foo:
python foo.py
And I run make foo, I get the output:
python foo.py
running foo
make: *** [foo] Error 1
So it detected the error.
If on the other hand, what you want to do is record the return value of a command in a Makefile, you can use the $? variable, which stores the last return value of a command.
A couple things to note:
$$? in the commandExample:
build:
python mySample.py ; echo $$? > output
After running make, you will have a file named output that contains the return value of mySample.py.
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