[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

STDOUT to StringIO

Fredrik

11/21/2007 9:13:00 AM

I know that I can redirect my standard output to a file like this:

STDOUT.reopen(File.open(filename,'w'))

But then, why can't I redirect it to a string like this? :

output = StringIO.open('','w')
STDOUT.reopen(output)
> TypeError: can't convert StringIO into String

Can somebody see what I am doing wrong?

Thanks a lot!
Fredrik
2 Answers

Ryan Davis

11/21/2007 10:18:00 AM

0


On Nov 21, 2007, at 01:15 , Fredrik wrote:

> I know that I can redirect my standard output to a file like this:
>
> STDOUT.reopen(File.open(filename,'w'))
>
> But then, why can't I redirect it to a string like this? :
>
> output = StringIO.open('','w')
> STDOUT.reopen(output)
>> TypeError: can't convert StringIO into String
>
> Can somebody see what I am doing wrong?

>> $stderr = output
=> #<StringIO:0x404e8>
>> warn "blah"
=> nil
>> output.string
=> "blah\n"



Eric Hodel

11/21/2007 9:10:00 PM

0

On Nov 21, 2007, at 02:18 , Ryan Davis wrote:
> On Nov 21, 2007, at 01:15 , Fredrik wrote:
>
>> I know that I can redirect my standard output to a file like this:
>>
>> STDOUT.reopen(File.open(filename,'w'))
>>
>> But then, why can't I redirect it to a string like this? :
>>
>> output = StringIO.open('','w')
>> STDOUT.reopen(output)
>>> TypeError: can't convert StringIO into String
>>
>> Can somebody see what I am doing wrong?
>
> >> $stderr = output
> => #<StringIO:0x404e8>
> >> warn "blah"
> => nil
> >> output.string
> => "blah\n"

Also:

http://blog.segment7.net/articles/2006/08/17/stdout...

--
Poor workers blame their tools. Good workers build better tools. The
best workers get their tools to do the work for them. -- Syndicate Wars