Python subprocess readlines()?
ls = subprocess.Popen(['ls','-l'], stdout=subprocess.PIPE)
out = ls.stdout.readlines()
or, if you want to read line-by-line (maybe the other process is more intensive than ls
):
for ln in ls.stdout:
# whatever
With subprocess.Popen
, use communicate
to read and write data:
out, err = subprocess.Popen(['ls','-l'], stdout=subprocess.PIPE).communicate()
Then you can always split the string from the processes' stdout
with splitlines()
.
out = out.splitlines()