如何在子进程的python调用中捕获调用进程错误

问题描述 投票:0回答:1

尝试使用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))

但是我无法获得Segmentation故障消息

就我搜索而言,都没有找到所需的参数

python debugging subprocess
1个回答
0
投票

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

What actually prints "Segmentation fault"?

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

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

© www.soinside.com 2019 - 2024. All rights reserved.