PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > STDOUT to StringIO
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
STDOUT to StringIO

Réponse
 
LinkBack Outils de la discussion
Vieux 21/11/2007, 09h13   #1
Fredrik
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut STDOUT to StringIO

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
  Réponse avec citation
Vieux 21/11/2007, 10h18   #2
Ryan Davis
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: STDOUT to StringIO


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"



  Réponse avec citation
Vieux 21/11/2007, 21h09   #3
Eric Hodel
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: STDOUT to StringIO

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/20...dout-vs-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



  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 18h36.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09319 seconds with 11 queries