I have a python script which will do some actions, and depending on the result, will exit with a code 0 (all right) or 1 (not good).
I want to catch this result, store it into a variable and send it over UDP. This cannot be done inside the python script (requirement).
So let's say my script is something like:
# Do some stuff
sys.exit(0) # or sys.exit(1)
Since as per your answer you are using
import os os.exit(12)
in your console
python test.py RC=$? echo "Exit code $RC" program_to_send $RC