From: Simon Strandgaard Date: 2004-02-11T00:54:58+09:00 Subject: Re: capture stderr On Tue, 10 Feb 2004 08:17:06 -0700, Ara.T.Howard wrote: > On Tue, 10 Feb 2004, Simon Strandgaard wrote: >> From: Simon Strandgaard >> >> I want to temporarily capture stderr output. Im on a freebsd box, so pipe >> should work. > > a pipe should work - but it's pretty tricky... Yes I got the pipe working.. didn't you see my second mail? ;-) >> What am I doing wrong? > > * IO#read blocks until eof is read - your loop will only happen once and tries > to read all data at once. if you really wanted to do something like that > you'd need to do something like > > require 'io/nonblock' # i love this module I have not yet tried using this module module.. though I have experience with non-blocking io. [snip] > begin > $stderr = StringIO.new > yield > $stderr.rewind && $stderr.read > ensure > $stderr = STDERR > end Thanks.. I had forgotten the 'ensure' statement! My code is now looking like: def capture_stderr(&block) e = StringIO.new $stderr = e block.call return e.string ensure $stderr = STDERR end -- Simon Strandgaard