Filtering through an external process
Scott David Daniels
Scott.Daniels at Acm.Org
Mon Dec 1 20:08:15 EST 2003
Paul Rubin wrote:
> Anyone know if there's code around to filter text through an external
> process? Sort of like the Emacs "filter-region" command. For
Check out popen2 -- its the piece you need.
dest, result = os.popen2('cmd')
dest.write('echo Hello world\n')
dest.write('exit\n')
dest.close()
result.read()
So, perhaps you mean:
import os
def filtered(command, source):
dest, result = os.popen2(command)
dest.write(source)
dest.close()
try:
return result.read()
finally:
result.close()
-Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-list
mailing list