This question already has an answer here:
- 'yes' reporting error with subprocess communicate() 3 answers
- How to use `subprocess` command with pipes 6 answers
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
"grep: writing output: Broken pipe"
I'm not very familiar with the subprocess
module, I would like advice as to how to get this output, and what I am currently doing wrong.