Last active
October 13, 2016 09:35
-
-
Save webknjaz/b59aa9010fc76b229cf6a5233b3a895d to your computer and use it in GitHub Desktop.
POSIX return code processing example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
import sys | |
def main(): | |
arg = sys.argv[1] | |
if smth_went_wrong(arg): | |
return 1 # failure code | |
return 0 # POSIX success | |
sys.exit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://tldp.org/LDP/abs/html/comparison-ops.html | |
arg=`cat $1` | |
# case 1 | |
python script.py "$arg" | |
retcode=$? | |
if [ $retcode -eq 1 ]; then | |
# "==" is a string comparison, not integer | |
exit 0 | |
fi | |
# case 2 | |
python script.py "$arg" || exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment