On 20 Apr 2008, at 12:40, Xie Hanjian wrote:

> * James Tucker <jftucker / gmail.com> [2008-04-19 19:55:45 +0900]:
>
>>
>> On 19 Apr 2008, at 10:55, Michael Fellinger wrote:
>>
>>> On Sat, Apr 19, 2008 at 1:40 PM, Xie Hanjian <jan.h.xie / gmail.com>  
>>> wrote:
>>>> Hi,
>>>>
>>>> I'm afraid the problem is the same: you can't interact with the  
>>>> program
>>>> after data has been read. any function like getch() will try to  
>>>> read
>>>> input
>>>> from the file to which stdin was redirected instead of your  
>>>> console.
>>>
>>> You can check if you are getting data from a pipe by asking
>>> $stdin.tty? and act accordingly.
>>> See http://p.ramaze.net/1144 for a short example.
>>>
>>> Regarding platform compatibility, according to
>>> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/146259
>>> you can $stdin.reopen("COM1:")
>>
>> Make that CON: and you're on to a winner!
>>
>> dev = 'CON:'
>> [$stdin, $stdout].each {|io| io.reopen(dev)}
>> puts gets
>
> Not works here, only on windows?

Yes 'CON:' applies to windows, not to *nix. On other platforms, most  
of the time it should be /dev/tty.

dev = File::stat('/dev/tty') && '/dev/tty' rescue 'CON:'
[$stdin, $stdout].each { |io| io.reopen(dev) }
puts gets

>
>
> Actually I find this:
> http://www.a-k-r.org/ruby-terminfo/rdoc/classes/TermInfo.html#M000031
>
> Thanks all guys :-)
> Jan
>
>>
>> :-)
>>
>>> ^ manveru
>>
>>
>
> -- 
> jan=callcc{|jan|jan};jan.call(jan)