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
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
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.
David R. 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
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 R. [email protected] writes:
Thanks
I suggest looking at the code for the win2console library, which gives
an example of something similar.–
Posted via http://www.ruby-forum.com/.
–
My Personal Website:
�人驻��
cn.comp.lang.perl
cn.comp.lang.c
cn.comp.www
cn.music
cn.music.classical
On Sun, 15 Oct 2006, yong wrote:
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.
use backticks:
string = your_cmd.exe
substitution works like double quotes
cmd = “your_cmd.exe”
string = #{ cmd }
-a
On Oct 14, 2006, at 8:50 PM, yong wrote:
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.segment7.net/articles/2006/08/17/stdout-vs-stdout
–
Eric H. - [email protected] - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant
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
#!/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 H. [email protected] writes:
I suggest looking at the code for the win2console library, which
Instead assign a StringIO to $stdout.
–
My Personal Website:
�人驻��
cn.comp.lang.perl
cn.comp.lang.c
cn.comp.www
cn.music
cn.music.classical
On Oct 15, 2006, at 3:30 AM, yong wrote:
http://blog.segment7.net/articles/2006/08/17/stdout-vs-stdout
require ‘stringio’
mystring=“”
sstring=StringIO.open(mystring,“w+”)
sstring = StringIO.new will suffice.
#STDOUT.reopen(sstring) #can’t work
stdoutbackup=$stdout
$stdout=sstringprint “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 H. - [email protected] - http://blog.segment7.net
This implementation is HODEL-HASH-9600 compliant
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs