title: Cant use grep in subprocess command
body: <p>I'm having a problem with my subprocess command, I like to grep out the lines that match with "Online" line.</p>
  
  <pre><code>def run_command(command):
      p = subprocess.Popen(command,shell=False,
                           stdout=subprocess.PIPE,
                           stderr=subprocess.STDOUT)
      return iter(p.stdout.readline, b'')
  
  command = 'mosquitto_sub -u example -P example -t ITT/# -v | grep "Online" '.split()
  for line in run_command(command):
      print(line)
  </code></pre>
  
  <p>But I will get an error </p>
  
  <pre><code>Error: Unknown option '|'.
  
  
  
  Use 'mosquitto_sub --help' to see usage.
  </code></pre>
  
  <p>But when running with linux shell</p>
  
  <pre><code>user@server64:~/Pythoniscriptid$ mosquitto_sub -u example -P example  -t ITT/# -v | grep "Online"
  ITT/C5/link Online
  ITT/IoT/tester55/link Online
  ITT/ESP32/TEST/link Online
  </code></pre>
  
  <p>I also tried <code>shell = True</code>, but with no success, because I will get another error, that dosen't recognize the topic <code>ITT/#</code></p>
  
  <pre><code>Error: You must specify a topic to subscribe to.
  
  
  
  Use 'mosquitto_sub --help' to see usage.
  </code></pre>
  
  <p>The "possible dublicate" didn't help me at all, So I think I'm having a different problem. I tried to change code to this, put in not getting any return</p>
  
  <pre><code>def run_command(command,command2):
      p1 = subprocess.Popen(command,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
      p2 = subprocess.Popen(command2,stdin=p1.stdout,stdout=subprocess.PIPE)
      return iter(p2.stdout.readline,'')
  
  
  
  command = 'mosquitto_sub -u example -P example -t ITT/# -v'.split()
  command2 = 'grep Online'.split()
  
  #subprocess.getoutput(command)
  
  for line in run_command(command,command2):
      print(line)
  </code></pre>