Python subprocess.check_output, with pipeline
Question: I'm trying to get output of

    
    
    dmesg | grep -i 'bios'
    

I've tried this:

    
    
    dmsg = subprocess.check_output("dmesg | grep -i 'bios'").decode('utf-8')
    

, but I'm getting an error.

How can I obtain a full `sdtoutput` message?


Answer: 
    import subprocess
    
    p1 = subprocess.Popen(['dmesg'], stdout=subprocess.PIPE)
    
    p2 = subprocess.Popen(['grep', '-i', 'bios'], stdin=p1.stdout, stdout=subprocess.PIPE)
    
    p1.stdout.close()
    out, err = p2.communicate()
    
    print(out)
    

