From: Ken Bloom Date: 2009-09-22T11:08:42+09:00 Subject: Re: redirect STDOUT to function? On Tue, 22 Sep 2009 10:07:16 +0900, Jonathan Castello wrote: > Hello, > I'm using Ruby as a scripting language for a program that supports the > WSH scripting interface, and I have a small problem: 'puts' and other > output functions don't work (because STDOUT is invalid), as with 'gets' > (but with STDIN). I'd like to redirect all accesses to STDOUT and STDIN > to my own functions, which would handle the IO through the main > application's scripting interface. I know that $stdout and others can be > reassigned to other IO objects, but I haven't yet found a way to > reliably redirect through a function instead. Of course, this is > probably because I'm relatively new to Ruby. Does anyone know how I > could do something like this?~Jonathan Castello Create a brand new IO object that's backed by the function you want. (Maybe a thread and a StringIO would do the trick.) --Ken -- Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/