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