title: How can I get the output of a Timed Out command by subprocess.check_output()?
body: <p>I'm trying to run some commands using the python library subprocess. Some of my commands might get stuck in loops and block the python script. Therefore I'm using check_output() with a timeout argument to limit the commands in time. When the command takes too much time, the function raise a TimeoutExpired error. What I want to do is get what the command has been able to run before being killed by the timeout.</p>
  
  <p>I've except the error and tried "except sp.TimeoutExpired as e:". I read on the doc that if I do e.output it should give me what I want. "Output of the child process if this exception is raised by check_output(). Otherwise, None.". However I don't get anything in the output. </p>
  
  <p>Here is what I did: </p>
  
  <pre class="lang-py prettyprint-override"><code>import subprocess as sp
  try:
          out = sp.check_output('ls', stderr=sp.STDOUT, universal_newlines=True, timeout=1)
  except sp.TimeoutExpired as e:
          print ('output: '+ e.output)
  else:
          return out
  </code></pre>
  
  <p>Let say the folder I'm working with is huge and so 1 second isn't enough to ls all its files. Therefore the TimeoutExpired error will be raised. However, I'd like to store what the script was able to get at least. Does someone have an idea?</p>