Process substitution not allowed by Python's subprocess with shell=True?

/bin/sh: 1: Syntax error: "(" unexpected

You have a bashism. It is not valid according to POSIX, which is what /bin/sh implements.


An alternate solution is to shift more of the shell code to Python itself. For example:

from subprocess import Popen, PIPE, check_call

p1 = Popen(["pwd"], stdout=PIPE)
p2 = check_call(["wc", "-l"], stdin=p1.stdout)

This could often be the first step towards eliminating the need to use subprocess at all, as it decomposes the work into smaller chunks for which you may more readily see how to do in Python itself.