gpt4 book ai didi

python - 从 bash 脚本调用时获取 Python 命令行输出

转载 作者:太空宇宙 更新时间:2023-11-03 13:43:47 26 4
gpt4 key购买 nike

这可能是一个 super 简单的问题。我正在通过 shell 脚本在 Lubuntu OS (Cubietruck) 上调用 Python 脚本。这是为了使启动过程自动化(我想维护这个过程)。有没有一种简单的方法来查看 Python 的输出?目前 Python 脚本在后台运行,没有终端。我有一些错误需要检查。脚本是:

#!/bin/sh
python recordSound.py

提前致谢。

最佳答案

正确的解决方案可能是使用 logging正如评论中所提议的那样。

与此同时,您必须重定向标准输出和标准错误流,以便将正常输出捕获为墙作为您的脚本报告的任何错误:

#!/bin/sh
python recordSound.py >> logfile.log 2&>1

参见 one of the many web pages on that topic探索 shell 脚本中可用的各种重定向。


此外,如果您同时需要在控制台上登录 实时 View ,请使用tee标准命令:

#!/bin/sh
python recordSound.py 2&>1 | tee logfile.log

关于python - 从 bash 脚本调用时获取 Python 命令行输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24673096/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com