如何将程序的崩溃消息转储到文件中?
How to dump the crash message of a program into files?
例如,如果我有一个 python 文件 test.py
。
运行 python test.py
在命令行中崩溃并显示消息:
Segmentation Fault(core dumped)
如何使用脚本将此类消息保存到 txt 文件中? (假设我有test1.py、test2.py、test3.py...它们都崩溃了。我想收集它们的崩溃日志并做一些分析)
该消息来自 shell,而不是程序。如果你想捕获它,你需要 运行 subshell 中的命令,这样你就可以重定向 shell 的输出。您需要重定向 stderr 以获取错误消息。
for script in test*.py; do
(python "$script")
done 2>errors.txt
例如,如果我有一个 python 文件 test.py
。
运行 python test.py
在命令行中崩溃并显示消息:
Segmentation Fault(core dumped)
如何使用脚本将此类消息保存到 txt 文件中? (假设我有test1.py、test2.py、test3.py...它们都崩溃了。我想收集它们的崩溃日志并做一些分析)
该消息来自 shell,而不是程序。如果你想捕获它,你需要 运行 subshell 中的命令,这样你就可以重定向 shell 的输出。您需要重定向 stderr 以获取错误消息。
for script in test*.py; do
(python "$script")
done 2>errors.txt