From: Michael Fellinger Date: 2008-04-19T18:55:35+09:00 Subject: Re: What's the 'portable' way to do this? 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:") ^ manveru > > Thanks > Jan > > * Daniel Finnie [2008-04-19 02:08:11 +0900]: > > > > > Hi, > > > > I think ARGF might work for your needs: > > > > data = ARGF.read > > > > Give it a try, > > Dan > > > > On 4/17/08, Xie Hanjian wrote: > > > Hi, > > > > > > I want to know if there's a more 'portable' way to do this in ruby: > > > > > > I hope my programe will accept data from redirected stdin or pipe, like > > > > > > cat bar | foo.rb > > > foo.rb < bar > > > > > > And after read the data I want to interact with the foo.rb in console. > > > The problem is stdin has been redirected so I have to: > > > > > > STDIN.reopen('/dev/tty') > > > > > > Hardcoding a string in the script seems not good. Any suggestions? > > > > > > Thanks > > > Jan > > > > > > > > > -- > > > jan=callcc{|jan|jan};jan.call(jan) > > > > > > > > > > -- > > > jan=callcc{|jan|jan};jan.call(jan) >