import subprocess
p1 = subprocess.Popen(['echo', 'This_is_a_testing'], stdout=subprocess.PIPE)
p2 = subprocess.Popen(['grep', '-c', 'test'], stdin=p1.stdout)
1
p2.communicate()
Python - how to execute shell commands with pipe?