Handling exit code returned by python in shell script

后端 未结 3 1451
萌比男神i
萌比男神i 2020-12-10 04:23

I am calling a python script from within a shell script. The python script returns error codes in case of failures.

How do I handle these error codes in shell scrip

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-10 04:50

    You mean the $? variable?

    $ python -c 'import foobar' > /dev/null
    Traceback (most recent call last):
      File "", line 1, in 
    ImportError: No module named foobar
    $ echo $?
    1
    $ python -c 'import this' > /dev/null
    $ echo $?
    0
    

提交回复
热议问题