Redirecting Output of PIPE to a FILE in python
Following code is to redirect the output of the Pipe to a file "CONTENT"
and it has some content, I want to overwrite it with output of "sort
CONTENT1 | uniq ".... But I'm not able overwrite it and also i don't know
weather following code is redirecting to CONTENT(ie correct or not) or
not. Please help me out....
f1=open('CONTENT','w')
sys.stdout=f1
p1 = subprocess.Popen(["sort", "CONTENT1"], stdout=subprocess.PIPE)
p2 = subprocess.Popen(["uniq"], stdin=p1.stdout, stdout=subprocess.PIPE)
p1.stdout.close()
p2.communicate()
sys.stdout=sys.__stdout__
No comments:
Post a Comment