I want to get the exit status set in a shell script which has been called from Python.
The code is as below
result = os.system("./compile_cmd.sh")
print result
javac @source.txt
# I do some code here to get the number of compilation errors
if [$error1 -e 0 ]
then
echo "\n********** Java compilation successful **********"
exit 0
else
echo "\n** Java compilation error in file ** File not checked in to CVS **"
exit 1
fi
I am running this code, but no matter the what exit status I am returning, I am getting result var as 0 (I think it's returning whether the shell script ran successfully or not).
How can I fetch the exit status that I am setting in the shell script in the Python script?
import subprocess
result = subprocess.Popen("./compile_cmd.sh")
text = result.communicate()[0]
return_code = result.returncode
Taken from here: How to get exit code when using Python subprocess communicate method?
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