From: "list. rb" Date: 2008-10-21T11:42:20+09:00 Subject: Re: Block method to yield stdout? ------=_Part_25356_10965414.1224557017191 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Mon, Oct 20, 2008 at 5:13 PM, Mark Thomas wrote: > On Oct 20, 2:19 pm, "List.rb" wrote: > > > In my Task class, I would like to create a block method such as > > 'Task.monitor(mode="stdout")', which would yield the stdout for that > > task from that point forward. -- similar to tail -f > > Have you seen File::Tail? > http://file-tail.rubyforge.org/doc/index.html > > -- Mark. > > Thanks Mark for replying. Yes I have used Tail before but what I'm looking for is more along the lines of a non-blocking version of IO#readlines Currently, I do this on the server side: def spawn(job) task = Task.new(job) queue = Queue.new Thread.new(queue) {|q| pipe = IO.popen(task.job.cmd) q.push(pipe) q.push(pipe.pid) task.pid = pipe.pid begin Thread.new { task.output = pipe.readlines pipe.close task.exitstatus = $?.exitstatus task.history << {:completed => Time.now} } rescue => e q.push e end } queue.clear self.tasks.push(task) return task end Since IO#readlines blocks, I am not sure how to tap into the process output :-( Thanks again ------=_Part_25356_10965414.1224557017191--