【问题标题】:How to dump the crash message of a program into files?如何将程序的崩溃消息转储到文件中?
【发布时间】:2021-03-19 20:21:19
【问题描述】:

例如,如果我有一个 python 文件test.py

在命令行中运行 python test.py 会崩溃并显示消息:

Segmentation Fault(core dumped)

如何使用脚本将此类消息保存到 txt 文件中? (想象一下我有test1.py、test2.py、test3.py……它们都崩溃了。我想收集它们的崩溃日志并做一些分析)

【问题讨论】:

标签: python linux bash crash


【解决方案1】:

该消息来自外壳程序,而不是程序。如果要捕获它,则需要在子 shell 中运行命令,以便可以重定向 shell 的输出。您需要重定向 stderr 以获取错误消息。

for script in test*.py; do
    (python "$script")
done 2>errors.txt

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-26
    • 2018-10-22
    • 2017-01-15
    • 1970-01-01
    • 2016-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多