From: Venks Date: 2007-12-06T09:49:26+09:00 Subject: Re: Capturing STDOUT from a system call (POSIX) into an array Actually, the output is not in a file. The output is generated by a system call. I somehow think there is something simple in Ruby that I can use to covert the STDOUT to a 2 dimensional array without actually using any IO objects. On Dec 5, 2007 7:39 PM, Ken Bloom wrote: > > On Wed, 05 Dec 2007 18:57:51 -0500, Venks wrote: > > > What's the best way to capture STDOUT into an Array? I looked at popen3, > > open4, systemu but couldn't figure out how to do this. > > > > In short, I want to execute a system call like "ls -l" and capture it > > into an array. Of course, "ls -l" may not have proper delimiter but > > assume that the delimiter is TAB or COMMA. > > > > Thanks, > > You can use the IO objects returned by popen3 in any way that you'd use a > normal file. To get an array of lines, one string per line, use > #readlines. To parse it as a CSV, for example, the csv library in ruby > should work with CSV.parse > > --Ken > > -- > Ken (Chanoch) Bloom. PhD candidate. Linguistic Cognition Laboratory. > Department of Computer Science. Illinois Institute of Technology. > http://www.iit.edu/~kbloom1/ > >