Handling exit code returned by python in shell script

后端 未结 3 1459
萌比男神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:48

    Please use logic below to process script execution result:

    python myPythonScript.py
    # $? =  is the exit status of the most recently-executed command; by convention, 0 means success and anything else indicates failure. 
    if [ $? -eq 0 ]
    then
      echo "Successfully executed script"
    else
      # Redirect stdout from echo command to stderr.
      echo "Script exited with error." >&2
    fi
    

提交回复
热议问题