title: executing piped shell commands in python
body: <p>I need help with python code in executing multiple piped shell commands in python.
  I have written the following code but I am getting error. As I am passing the file to the command. Please let me know the correct process on how to execute multiple piped commands in python.</p>
  
  <pre><code>EG: cat file|grep -i hostname|grep -i fcid 
  </code></pre>
  
  <p>is the shell command I want to execute. Here is my python code. I am getting None when I run the code.I am redirecting the final output to a file.</p>
  
  <pre><code>#!/usr/bin/python3
  
  import subprocess
  
  op = open("text.txt",'w')
  file="rtp-gw1"
  
  print("file name is {}".format(file))
  #cat file|grep -i "rtp1-VIF"|grep -i "fcid"
  
  #cmd ='cat file|grep -i "rtp1-vif"'
  p1  = subprocess.Popen(['cat',file],stdout=subprocess.PIPE, stderr=subprocess.PIPE,shell=True)
  p2  = subprocess.Popen(['grep','-i', '"rtp1-vif"',file], stdin=p1.stdout, stdout=subprocess.PIPE,stderr= subprocess.PIPE,shell=Ture)
  p1.stdout.close()
  p3  = subprocess.Popen(['grep', '-i',"fcid"],stdin=p1.stdout, stdout=op,stderr= subprocess.PIPE,shell=Ture)
  p2.stdout.close()
  
  result = p3.communicate()[0]
  
  print(result)
  </code></pre>