Python command execution output
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/4760215/running-shell-command-from-python-and-capturing-the-output">Running shell command from python and capturing the output</a>  </p>
</blockquote>



<p>I want to capture the output of a command into a variable, so later that variable can be used again. I need to change this script so it does that:</p>

<pre><code>#!/usr/bin/python
import os
command = raw_input("Enter command: ")
os.system(command)
</code></pre>

<p>If I enter "ls" when I run this script, I get this output:</p>

<pre><code>Documents Downloads Music Pictures Public Templates Videos
</code></pre>

<p>I want to capture that string (the output of the ls command) into a variable so I can use it again later. How do I do this?</p>
