在 Korn shell 中,我调用了一个 python 程序,并将所有内容记录到 $workfile:
python3 crontab_search.py | tee $workfile
在 Python 程序 crontab_search.py 中,我退出并返回返回码:
sys.exit(1)
如果我删除 T 恤,我会得到正确的返回代码,但我无法通过 T 恤获取代码。
这有效:
python3 crontab_search.py; echo $? | tee $workfile
但这不起作用:
python3 crontab_search.py; returncode=$? | tee $workfile
我想根据返回码的值做一些额外的事情。
谢谢。
最佳答案
不是 Korn-shell 专家,而是来自 here 的管道故障解决方案也应该在 ksh 中工作。 (显然,还有单独执行的。)
关于unix - 通过重定向输出从 Python 脚本获取退出代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17560961/