Using subprocess to get output of grep piped through head -1 [duplicate]
问题 This question already has answers here : 'yes' reporting error with subprocess communicate() (3 answers) How to use `subprocess` command with pipes (7 answers) Closed 4 years ago . The gist of what I'm trying to do is this: grep -n "some phrase" {some file path} | head -1 I would like to pass the output of this into python. What I've tried so far is: p = subprocess.Popen('grep -n "some phrase" {some file path} | head -1',shell=True,stdout=subprocess.PIPE) I get back a lot of messages saying