title: Output from subprocess.Popen
body: <p>I have been writing some python code and in my code I was using &quot;command&quot;</p>
  <p>The code was working as I intended but then I noticed in the Python docs that command has been deprecated and will be removed in Python 3 and that I should use &quot;subprocess&quot; instead.</p>
  <p>&quot;OK&quot; I think, &quot;I don't want my code to go straight to legacy status, so I should change that right now.</p>
  <p>The thing is that <code>subprocess.Popen</code> seems to prepend a nasty string to the start of any output e.g.</p>
  <pre><code>&lt;subprocess.Popen object at 0xb7394c8c&gt;
  </code></pre>
  <p>All the examples I see have it there, it seems to be accepted as given that it is always there.</p>
  <p>This code;</p>
  <pre><code>#!/usr/bin/python
  import subprocess
  output = subprocess.Popen(&quot;ls -al&quot;, shell=True)
  print output
  </code></pre>
  <p>produces this;</p>
  <pre><code>&lt;subprocess.Popen object at 0xb734b26c&gt;
  brettg@underworld:~/dev$ total 52
  drwxr-xr-x  3 brettg brettg 4096 2011-05-27 12:38 .
  drwxr-xr-x 21 brettg brettg 4096 2011-05-24 17:40 ..
  &lt;trunc&gt;
  </code></pre>
  <p>Is this normal? If I use it as part of a larger program that outputs various formatted details to the console it messes everything up.</p>
  <p>I'm using the command to obtain the IP address for an interface by using ifconfig along with various greps and awks to scrape the address.</p>
  <p>Consider this code;</p>
  <pre><code>#!/usr/bin/python
  import commands,subprocess
  
  def new_get_ip (netif):
  address = subprocess.Popen(&quot;/sbin/ifconfig &quot; + netif + &quot; | grep inet | grep -v inet6 | awk '{print $2}' | sed 's/addr://'i&quot;, shell=True)
  return address
  
  def old_get_ip (netif):
  address = commands.getoutput(&quot;/sbin/ifconfig &quot; + netif + &quot; | grep inet | grep -v inet6 | awk '{print $2}' | sed 's/addr://'i&quot;)
  return address
  
  print &quot;OLD IP is :&quot;,old_get_ip(&quot;eth0&quot;)
  print &quot;&quot;
  print &quot;NEW IP is :&quot;,new_get_ip(&quot;eth0&quot;)
  </code></pre>
  <p>This returns;</p>
  <pre><code>brettg@underworld:~/dev$ ./IPAddress.py
  OLD IP is : 10.48.16.60
  
  NEW IP is : &lt;subprocess.Popen object at 0xb744270c&gt;
  brettg@underworld:~/dev$ 10.48.16.60
  </code></pre>
  <p>Which is fugly to say the least.</p>
  <p>Obviously I am missing something here. I am new to Python of course so I'm sure it is me doing the wrong thing but various google searches have been fruitless to this point.</p>
  <p>What if I want cleaner output? Do I have to manually trim the offending output or am I invoking <code>subprocess.Popen</code> incorrectly?</p>