unix - 通过重定向输出从 Python 脚本获取退出代码

标签 unix python-3.x ksh

在 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/

相关文章:

unix - 目录路径变量是否应该以斜杠结尾?

python - 当字符串列表交换为文本文件时程序停止工作

python - 我的 Flask 应用程序中出现 RuntimeError : Working outside of application context.

shell - 在 ksh 中混合 "nounset"和 "$@"

C - Windows 和 Unix 上的可移植代码

python - 在 Unix 中基于部分匹配删除文件

c - 套接字编程 TCP 。服务器编程不断循环

Python - 用于将某些行写入新文件的 CSV 模块

string - KornShell Printf - 填充字符串

linux + 什么是合并文件的最佳方式