Pipes
os.popen() function
f = popen("ls -l", "r")
data = f.read()
f.close()
Opens a pipe to or from a command and returns a file-object.
The popen2 module
- Spawns processes and provides hooks to stdin, stdout, and stderr
popen2(cmd) # Run cmd and return (stdout, stdin)
popen3(cmd) # Run cmd and return (stdout, stdin, stderr)
- Example
(o,i) = popen2.popen2("wc")
i.write(data) # Write to child's input
i.close()
result = o.read() # Get child's output
o.close()
|