From: James Tucker Date: 2008-04-19T19:55:45+09:00 Subject: Re: What's the 'portable' way to do this? On 19 Apr 2008, at 10:55, Michael Fellinger wrote: > On Sat, Apr 19, 2008 at 1:40 PM, Xie Hanjian > 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 :-) > ^ manveru