subprocess replacement of popen2 with Python -
i tried run code book 'python standard library' of 'fred lunde'.
import popen2, string  fin, fout = popen2.popen2("sort")  fout.write("foo\n") fout.write("bar\n") fout.close()  print fin.readline(), print fin.readline(), fin.close()   it runs warning of
~/python_standard_library_oreilly_lunde/scripts/popen2-example-1.py:1: deprecationwarning: popen2 module deprecated. use subprocess module.
how translate previous function subprocess? tried follows, doesn't work.
from subprocess import *  p = popen("sort", shell=true, stdin=pipe, stdout=pipe, close_fds=true)  p.stdin("foo\n")                #p.stdin("bar\n")      
import subprocess proc=subprocess.popen(['sort'],stdin=subprocess.pipe,stdout=subprocess.pipe) proc.stdin.write('foo\n') proc.stdin.write('bar\n') out,err=proc.communicate() print(out)      
Comments
Post a Comment