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