【问题标题】:How to catch call process error in python call with subprocess如何在使用子进程的python调用中捕获调用进程错误
【发布时间】:2019-02-22 20:38:51
【问题描述】:

尝试在 python 上使用脚本调试程序(缓冲区溢出)我需要恢复程序可能发送的所有消息。

在 Linux 上,在终端上正常调用 ./a.out AAA 回应

你的论点是:AAA

带有溢出输入:./a.out AAAAAAA 回应

你的论点是:AAAAAAA

分段错误

我构建python代码如下

import sys, string, os
from subprocess import Popen, PIPE

processName = os.getcwd() + "/a.out"
argument = "AAAAAAAAA"

p = Popen([processName, argument], stdout=PIPE, stderr=PIPE)
output, error = p.communicate()
print(":: %d %s %s" % (p.returncode, output, error))

但我无法收到分段错误消息

据我搜索,没有找到需要的参数

【问题讨论】:

标签: python debugging subprocess


【解决方案1】:

该过程实际上并不打印Segmentation fault。当您从 shell 运行 a.out 时,这实际上是由 shell 本身产生的。所以,这不是你的程序产生的消息。

What actually prints "Segmentation fault"?

但是,您可以通过比较 p.returncode-signal.SIGSEGV 模块中的 -signal.SIGSEGV 来检查进程的返回代码,以查看它是否因分段错误而停止,有关详细信息,请参阅下面链接的问题。

这个问题可能与Capture "Segmentation fault" message for a crashed subprocess: no out and err after a call to communicate()重复

【讨论】:

    猜你喜欢
    • 2021-02-22
    • 1970-01-01
    • 1970-01-01
    • 2015-05-31
    • 2018-02-05
    • 1970-01-01
    • 2013-01-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多