'How to do action based on status code in ssh?

I want to do some action based on the status code from one of the commands in ssh.

For example, I have the below ssh command.

python $BASEDIR/Demo.py --message hello --environment test

So, now the above Demo.py gives status code 1 and 0.

So, if the status code is 1 then I want to execute some other command if it is 0 then I want to exit from ssh.

How can I do the same?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source