Mornor Mornor - 5 months ago 51
Bash Question

Get exit status code from Python

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:

import sys
# Do some stuff
sys.exit(0) # or sys.exit(1)

Which I run with

How can I get this exit status code (0 or 1).

I try to echo
, but it only print a blank line. Also try to use
instead of
(see here) and some other unsuccessful attempts.


Since as per your answer you are using zsh

import os

in your console

echo "Exit code $RC"
program_to_send $RC