I am trying to figure out what happens in subprocess
.
So, I write this code:
import subprocess
p1 = subprocess.Popen('grep a', stdin=subprocess.PIPE, stdout=subprocess.PIPE,shell=True, universal_newlines=True)
p2 = subprocess.Popen('grep a', stdin=p1.stdout, stdout=open('test', 'w'),shell=True, universal_newlines=True)
p1.stdin.write("asdads"*700)
After I write the string to p1.stdin
, I expected the string to be written to the file test
.
But there is nothing in the file.
When I tried another way:
out, err = p1.communicate("adsad"*700)
The string is in out
.