Das Python-Unterprozessmodul gibt bei segfault nicht stdout zurück

Ich verwende eine ausführbare C-Datei von Python und diese ausführbare Datei ist manchmal fehlerhaft. Wenn es segfaults ist, gibt das Unterprozessmodul nichts in stdout oder stderr zurück.

Beispielcode:

<code>import subprocess

proc = subprocess.Popen(['./a.out'], stdin=subprocess.PIPE,
        stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = proc.communicate()
print 'out: "%s"' % out
print 'err: "%s"' % err
print proc.returncode
</code>

Die Quelle füra.out ist:

<code>int main() {
    printf("hello world\n");
    int x = 1 / 0;
}
</code>

Die Ausgabe von./a.out ist:

<code>hello world
Floating point exception
</code>

Die Ausgabe des Python-Codes lautet (unter Linux, Python 2.7):

<code>out: ""
err: ""
-8
</code>

Gibt es eine Möglichkeit, die Ausgabe der ausführbaren Datei auch dann abzurufen, wenn sie abstürzt?

Eine generische Methode, um Returncode in eine String-Nachricht zu übersetzen, wäre auch schön.

Antworten auf die Frage(2)

Ihre Antwort auf die Frage