[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

redirect STDOUT

Luo Yong

10/14/2006 9:33:00 AM


Hi all

I'm writting a program to detect the cursor position with the vt100 command "\x1b[6n".

So I need to redirect STDOUT to a string.

How can I do this?

Thanks
9 Answers

David Roberts

10/14/2006 9:11:00 PM

0

yong wrote:
> Hi all
>
> I'm writting a program to detect the cursor position with the vt100
> command "\x1b[6n".
>
> So I need to redirect STDOUT to a string.
>
> How can I do this?
>
> Thanks

I suggest looking at the code for the win2console library, which gives
an example of something similar.


--
Posted via http://www.ruby-....

David Roberts

10/14/2006 9:13:00 PM

0

David Roberts wrote:
> yong wrote:
>> Hi all
>>
>> I'm writting a program to detect the cursor position with the vt100
>> command "\x1b[6n".
>>
>> So I need to redirect STDOUT to a string.
>>
>> How can I do this?
>>
>> Thanks
>
> I suggest looking at the code for the win2console library, which gives
> an example of something similar.

Oh bother! That should be "win32console".

DJ

--
Posted via http://www.ruby-....

Luo Yong

10/15/2006 3:49:00 AM

0


Thank you very much.

Now I can use STDOUT.reopen to redirect STDOUT output to a file.But How can I redirect it to a string?

Thanks.



David Roberts <smartgpx@gmail.com> writes:

> yong wrote:
>> Hi all
>>
>> I'm writting a program to detect the cursor position with the vt100
>> command "\x1b[6n".
>>
>> So I need to redirect STDOUT to a string.
>>
>> How can I do this?
>>
>> Thanks
>
> I suggest looking at the code for the win2console library, which gives
> an example of something similar.
>
>
> --
> Posted via http://www.ruby-....
>

--
My Personal Website:

http://www.tw...

�人驻��

cn.comp.lang.perl
cn.comp.lang.c
cn.comp.www
cn.music
cn.music.classical

Ara.T.Howard

10/15/2006 4:24:00 AM

0

David Roberts

10/15/2006 8:57:00 AM

0

yong wrote:

> Now I can use STDOUT.reopen to redirect STDOUT output to a file.But How
> can I redirect it to a string?
>

see "ri StringIO"

DJ

--
Posted via http://www.ruby-....

Eric Hodel

10/15/2006 9:06:00 AM

0

On Oct 14, 2006, at 8:50 PM, yong wrote:
> David Roberts <smartgpx@gmail.com> writes:
>> yong wrote:
>>> I'm writting a program to detect the cursor position with the vt100
>>> command "\x1b[6n".
>>>
>>> So I need to redirect STDOUT to a string.
>>>
>>> How can I do this?
>>
>> I suggest looking at the code for the win2console library, which
>> gives
>> an example of something similar.
>
> Now I can use STDOUT.reopen to redirect STDOUT output to a file.But
> How can I redirect it to a string?

You don't.

You should avoid touching STDOUT and STDERR as much as possible.

Instead assign a StringIO to $stdout.

http://blog.se.../articles/2006/08/17/stdout...

--
Eric Hodel - drbrain@segment7.net - http://blog.se...
This implementation is HODEL-HASH-9600 compliant

http://trackmap.rob...



Luo Yong

10/15/2006 10:30:00 AM

0



>>>
#!/usr/bin/ruby

require 'stringio'

mystring=""
sstring=StringIO.open(mystring,"w+")

#STDOUT.reopen(sstring) #can't work
stdoutbackup=$stdout
$stdout=sstring

print "BUFFERED TEXT\r\n"

$stdout=stdoutbackup
print mystring
<<<

It works.

Thank you very much. :)


Eric Hodel <drbrain@segment7.net> writes:

> On Oct 14, 2006, at 8:50 PM, yong wrote:
>> David Roberts <smartgpx@gmail.com> writes:
>>> yong wrote:
>>>> I'm writting a program to detect the cursor position with the vt100
>>>> command "\x1b[6n".
>>>>
>>>> So I need to redirect STDOUT to a string.
>>>>
>>>> How can I do this?
>>>
>>> I suggest looking at the code for the win2console library, which
>>> gives
>>> an example of something similar.
>>
>> Now I can use STDOUT.reopen to redirect STDOUT output to a file.But
>> How can I redirect it to a string?
>
> You don't.
>
> You should avoid touching STDOUT and STDERR as much as possible.
>
> Instead assign a StringIO to $stdout.
>
> http://blog.se.../articles/2006/08/17/stdout...
>
> --
> Eric Hodel - drbrain@segment7.net - http://blog.se...
> This implementation is HODEL-HASH-9600 compliant
>
> http://trackmap.rob...
>
>
>

--
My Personal Website:

http://www.tw...

�人驻��

cn.comp.lang.perl
cn.comp.lang.c
cn.comp.www
cn.music
cn.music.classical

Eric Hodel

10/15/2006 9:13:00 PM

0

On Oct 15, 2006, at 3:30 AM, yong wrote:
> Eric Hodel <drbrain@segment7.net> writes:
>> On Oct 14, 2006, at 8:50 PM, yong wrote:
>>> Now I can use STDOUT.reopen to redirect STDOUT output to a file.But
>>> How can I redirect it to a string?
>>
>> You don't.
>>
>> You should avoid touching STDOUT and STDERR as much as possible.
>>
>> Instead assign a StringIO to $stdout.
>>
>> http://blog.se.../articles/2006/08/17/stdout...
>
> require 'stringio'
>
> mystring=""
> sstring=StringIO.open(mystring,"w+")

sstring = StringIO.new will suffice.

> #STDOUT.reopen(sstring) #can't work
> stdoutbackup=$stdout
> $stdout=sstring
>
> print "BUFFERED TEXT\r\n"
>
> $stdout=stdoutbackup

I tend to wrap this up in a method that yields. See util_capture in
ZenTest's test/zentest_assertions.rb

--
Eric Hodel - drbrain@segment7.net - http://blog.se...
This implementation is HODEL-HASH-9600 compliant

http://trackmap.rob...



I L. Gregg

9/13/2013 2:54:00 AM

0

"Denny" is a Socialist-Communist Troll, a moderately retarded fool,
and a poor liar.

From: dzweibach@REMOVEyahoo.com (Denny)
X-No-Archive: yes

----------
Everything you need to know about 'Denny':
>Bret Cahill <BretCahill@peoplepc.com> wrote:
>> Holder needs to go after W. Bush & Cheney for using the IRS against
>> anti-quagmire activists and after they are safely behind bars then
>> we'll discuss Obama.
>...Those two have problems enough. We've all heard the rumors...Screaming
>nightmares, heavy drug use...leave them alone, let them suffer. Every time
>one of them see a Wounded Warrior ad on TV, their handlers have to hit them
>with the needle.
>MAY EVERY WAR-SUPPORTING RIGHT-WINGER SUFFER THE SAME.
[Emphasis mine - PG.]
----------

"Denny" posts a lot like a new version of that old brain-damaged idiot
"Ray Fischer."

Please note that when you reply to a Liar you encourage them to
continue lying.

[][][][][][]
The DemocRATs Hall Of Shame asks "Why do you always LIE?"

[Courtesy of Buster Norris]

On 03 Sep 2013 17:48:21 GMT, dzweibach@REMOVEyahoo.com (Denny) wrote:
>The president was smart to ask for a Congressional Resolution.
>If the House Republicans vote for an attack, their Tea Party constituents
>will barbecue them for agreeing with the President on anything. If they
>vote against, the President will just say "I tried but the cowardly GOP
>doesn't care about the suffering people of Syria.

LIAR!!!!!!!!!!!!!!!!!!!

Obama made clear that he thinks he already has the authority to take
action against Syria, even without the approval of Congress.
http://minnesota.publicradio.org/display/web/2013/09/03/daily-circuit-s...

Obogus said he doesn't need approval so if he doesn't get it and
doesn't attack HE'S A COWARD LAUGHINGSTOCK LIAR!!!!!!!!!!!!!

Posted on behalf of:
The DemocRATs Hall of Shame!