title: Capture "Segmentation fault" message for a crashed subprocess: no out and err after a call to communicate()
body: <p>I have problems using the subprocess module to obtain the output of crashed programs.
  I'm using python2.7 and subprocess to call a program with strange arguments in order to get some segfaults
  In order to call the program, I use the following code:</p>
  <pre><code>proc = (subprocess.Popen(called,
                           stdout=subprocess.PIPE,
                           stderr=subprocess.PIPE))
  out,err=proc.communicate()
  print out,err
  </code></pre>
  <p>called is a list containing the name of the program and the argument (a string containing random bytes except the NULL byte which subprocess doesn't like at all)</p>
  <p>The code behave and show me the stdout and stderr when the program doesn't crash, but when it does crash, out and err are empty instead of showing the famous &quot;Segmentation fault&quot;.</p>
  <p>I wish to find a way to obtain out and err even when the program crash.</p>
  <p>I also tried the check_output / call / check_call methods</p>
  <p>Some additional information:</p>
  <ul>
  <li><p>I'm running this script on an Archlinux 64 bits in a python virtual environment (shouldn't be something important here, but you never know :p)</p>
  </li>
  <li><p>The segfault happens in the C program I'm trying to run and is a consequence of a buffer overflow</p>
  </li>
  <li><p>The problem is that when the segfault occurs, I can't get the output of what happened with subprocess</p>
  </li>
  <li><p>I get the returncode right: -11 (SIGSEGV)</p>
  </li>
  <li><p>Using python i get:</p>
  <pre><code>  ./dumb2 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 
    ('Exit code was:', -11) 
    ('Output was:', '') 
    ('Errors were:', '')
  </code></pre>
  </li>
  <li><p>While outside python I get:</p>
  <pre><code> ./dumb2 $(perl -e &quot;print 'A'x50&quot;)  
   BEGINNING OF PROGRAM 
   AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
   END OF THE PROGRAM
   Segmentation fault (core dumped)
  </code></pre>
  </li>
  <li><p>The return value of the shell is the same: echo $? returns 139 so -11 ($? &amp; 128)</p>
  </li>
  </ul>