import subprocess PIPE = subprocess.PIPE cmd = 'ping google.com -n 20' p = subprocess.Popen(cmd, shell=False, stdin=PIPE, stdout=PIPE, stderr=subprocess.STDOUT) for line in p.stdout: print line,
import subprocess PIPE = subprocess.PIPE cmd = 'ping google.com -n 20' p = subprocess.Popen(cmd, shell=False, stdin=PIPE, stdout=PIPE, stderr=subprocess.STDOUT) for line in p.stdout: print line,
for line in iter(p.stdout.readline,''): print line,
line = 'Ping:' while line: line = p.stdout.readline() print line,
http://docs.python.org/library/stdtypes.html#bltin-file-objects
In order to make a for loop the most efficient way of looping over the lines of a file (a very common operation), the next() method uses a hidden read-ahead buffer
With the 3.0 version, the built-in open() is an alias for io.open;И куда совать этот io.open?
with 2.6, you have to use io.open() explicitely.