sh 处理从bash脚本启动的python脚本的错误

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 处理从bash脚本启动的python脚本的错误相关的知识,希望对你有一定的参考价值。

#!/usr/bin/python3

def main():	
	# define list
	l = []
	# validate list
	assert not len(l)==0, "error: the list is empty"


if __name__ == '__main__':
	try:
		# display
		print("[foo.py] beginning")
		# launch function
		main()
	finally:
		# display
		print("[foo.py] end")
#!/bin/bash

## definitions
PYTHON="/usr/bin/python3"

## functions
function controlerror {
	if [ $1 -eq 0 ]
	then
	  echo "The script ran ok"
	  #exit 0
	else
	  echo "The script failed" >&2
	  exit 1
	fi
} 

# display
echo "[launcher.sh] beginning"

# launch python script
$PYTHON foo.py
# control errors
controlerror $?


# display
echo "[launcher.sh] end"
# end
exit 0

以上是关于sh 处理从bash脚本启动的python脚本的错误的主要内容,如果未能解决你的问题,请参考以下文章