# read the lines one by one, as with other forms of I/O streams, and close the streamls = IO.popen("dir", "r")while line = ls.gets puts lineendls.close