Python 2.6: Get input from bash command with Popen and communicate and store as variable
Question: I need to get the input from a Bash command and store it as a Python variable
(sprice; a single float). On Python 2.7 the following works well:

    
    
    bashCommand = "curl -s 'http://download.finance.yahoo.com/d/quotes.csv?s=vwrl.as&f=l1'"
    sprice = float(subprocess.check_output(bashCommand, shell=True))
    

However on **Python 2.6 check_output isn't available**. Instead we have to
use:

    
    
    proc = Popen(['curl', '-s', 'http://download.finance.yahoo.com/d/quotes.csv?s=vwrl.as&f=l1'], stdout=PIPE)
    print (proc.communicate()[0].split())
    

Which shows the float we're after, enclosed by brackets.

    
    
    ['40.365']
    

Which is all right if I want to see the output and be done. But I need to
**store it in a Python variable like in the previous (2.7) case**. However
when I try to assign it to a variable I get:

    
    
    Traceback (most recent call last):   
      File "arr.py", line 49, in <module>
        sprice = proc.communicate()[0].split()
      File "/usr/lib/python2.7/subprocess.py", line 791, in communicate
        stdout = _eintr_retry_call(self.stdout.read)
      File "/usr/lib/python2.7/subprocess.py", line 476, in _eintr_retry_call
        return func(*args)
    ValueError: I/O operation on closed file
    

**Which is the proper way to do this?**


Answer: 
    import commands
    status, output = commands.getstatusoutput("curl -s http://download.finance.yahoo.com/d/quotes.csv?s=iwda.as&f=l1")
    

From [the
docs](https://docs.python.org/2/library/commands.html#commands.getstatusoutput):

> Execute the string cmd in a shell with os.popen() and return a 2-tuple
> (status, output). cmd is actually run as { cmd ; } 2>&1, so that the
> returned output will contain output or error messages.

