How to get correct exit code from Python

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sunyao
    New Member
    • Sep 2006
    • 2

    #1

    How to get correct exit code from Python

    Hi Friend,

    I write a linux shell script to call a python script inside. But I got a wrong exit code from Python exit code. The linux shell script as follows;

    #!/bin/bash
    MyPython.py
    exit $?

    After run the above linux script, I always got exit code 0. But autually the Python log file shows that its exit code is 256. In python script, use sys.exit(256).

    My question is how linux script can get the correct Python exit code?
    Thanks for your help.

    Sunny
  • kudos
    Recognized Expert New Member
    • Jul 2006
    • 127

    #2
    just a wild guess, maybe it have something to do that error codes are usigned bytes, i.e in the range [0,255], so that it interpret the exit value 256 as 0?



    Originally posted by sunyao
    Hi Friend,

    I write a linux shell script to call a python script inside. But I got a wrong exit code from Python exit code. The linux shell script as follows;

    #!/bin/bash
    MyPython.py
    exit $?

    After run the above linux script, I always got exit code 0. But autually the Python log file shows that its exit code is 256. In python script, use sys.exit(256).

    My question is how linux script can get the correct Python exit code?
    Thanks for your help.

    Sunny

    Comment

    • sunyao
      New Member
      • Sep 2006
      • 2

      #3
      Hi Kudos,

      Thanks for your response. I will try using other value.
      Thanks again.

      Sunny

      Comment

      Working...