【问题标题】:Capture python output from nested bash call? [duplicate]从嵌套的 bash 调用中捕获 python 输出? [复制]
【发布时间】:2020-03-11 01:35:35
【问题描述】:

我有一些 python 函数可以打印一些输出状态消息。然后我有一个 bash 脚本,run_python.sh,它按顺序调用这些 python 脚本,并在其中包含set -e 参数,因此如果出现任何故障,它就会失败。我需要使用参数列表调用该脚本(run_python.sh),并且我想捕获所有这些东西的输出

所以我有 call_run_python.sh 使用参数调用 run_python。

像这样运行call_run_python.sh 2>&1 | tee log.txt

我唯一的问题是现在我没有在输出中得到 python 脚本的输出。是否需要进行一些额外的重定向?我从run_python.sh 中的echo 语句中获得输出,但没有从同一脚本调用的python 输出

【问题讨论】:

    标签: python bash stdout


    【解决方案1】:

    您可以使用以下方法使输出不被缓冲

    stdbuf -o 0 python test.py 2>&1 |  tee out1.txt
    

    (见:https://repl.it/@JoranBeasley/UnacceptableSlateblueStack

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      • 2018-12-30
      • 2022-11-25
      • 2013-05-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多